惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 南桥一梦

Windows Hyper-v 开启嵌套虚拟化的方法 MySQL命令记录 Windows Server 2019 安装Windows Docker和.NET Framework 4.8镜像 Windows Docker 固定容器IP地址 透明网络驱动程序 MySQL优化 右键菜单怎样添加“在此处打开命令提示符”选项 MemSQL与MySQL不兼容问题总结 Ubuntu Server 18.04 修改网路配置 How to Install MemSQL Metro UI 菜单(Winform) Windows Server 2008 系统设置集合 Ubuntu 12.04和MySQL5.5安装 MySQL 参数设置 VS中如何自定义新建文件模板(添加自定义版权信息) Microsoft Windows Server 2008 R2 CHS 官方最新正版下载 在Hyper-V中安装和配置Ubuntu Server 11.04 10.10 解决WebClient或HttpWebRequest首次连接缓慢问题 Ubuntu MySQL Master-Master InnoDb Utf-8 配置文件 HOWTO:为 Hyper-V 配置外部网络
Ubuntu MySQL热备份安装
南桥一梦 · 2011-10-14 · via 博客园 - 南桥一梦

参考资料:

  http://www.cnblogs.com/wuhou/archive/2008/09/28/1301071.html

  http://www.hebaodans.com/2009/02/m-y-s-q-l-shu-ju-ku-de-tong-bu-wen-ti-shuang-ji-re-bei/

1.安装最新的Ubuntu Server版本,并更新系统。

2.安装MySQL Server:sudo apt-get instal mysql-server,然后设置管理员密码,去掉本地地址绑定,以便可以进行远程访问。

主:192.168.137.12

从:192.168.137.13

3.设置utf8字符集来支持中文,在主从服务器的配置文件/etc/mysql/my.cnf中加入:

[client]
default-character-set   = utf8

[mysqld]
default-character-set   = utf8

init_connect    = 'SET NAMES utf8;'

4.在服务器中启动备份。首先在主服务器在配置文件中添加下面的内容。其中s3(举个例子)为需要同步的数据库。

 

[mysqld]

log-bin         = mysql-bin
server-id       = 1
binlog-do-db    = s3

5.重新启动主数据库。

sudo service start mysql

6.连接到主数据库,并创建你需要同步的数据库,如果已经存在可以忽略这一步。

mysql –u root –p

create database s3;

7.在服务器中添加一个账号(sync)用于同步数据库,并赋予从备份的权限,重要。

grant replication slave on *.* to 'sync'@'%' identified by '12345'

8.记录s3数据库的日志文件名称和位置,用于从机备份开始的位置。

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000007 |      106 | s3           |                  |
+------------------+----------+--------------+------------------+

9.修改从机的配置文件。

[mysqld]
server-id       = 2
read-only
master-connect-retry     = 60
replicate-do-db = s3

10.重新启动从机,新建数据库(s3)或者从原来的数据库恢复数据库。并执行命令:

change master to MASTER_HOST='192.168.137.12', MASTER_USER='sync',MASTER_PASSWORD='12345',MASTER_LOG_FILE='mysql-bin.000007',MASTER_LOG_POS=106;

11.启动从机备份,并查看从机状态。

start slave;

show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.137.12
                  Master_User: sync
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000007
          Read_Master_Log_Pos: 106
               Relay_Log_File: S3-DB-SLAVE-1-relay-bin.000010
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000007
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: s3
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 559
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)

    Slave_IO_Running: Yes 
    Slave_SQL_Running: Yes

表示工作正常,否者出现问题。出现问题重要的解决工具是查看日志记录。

cat /var/log/mysql/error.log