- 同步原理
- master将改变记录到二进制日志(binary log)中
- slave将master的binary log events拷贝到它的中继日志(relay log)
- slave重做中继日志中的事件,改变自己的数据,相当于执行了master的所有操作
- 同步配置
- master配置
-
开启binlog vim /etc/my.cnf添加配置
12log_bin = mysql-bin
server_id = 1
-
创建复制账号
1GRANT
REPLICATION SLAVE,RELOAD,SUPER
ON
*.*
TO
root@’slave ip’ IDENTIFIED
BY
'password'
;
-
- 拷贝数据,如果master有数据而slave没有数据 则需要先把master的数据拷dump到slave中,如果是全新的master和slave(master和slave均没有数据则不需要此步骤)
- slave配置
-
对master运行
123456SHOW MASTER STATUS;
+
------------------+-----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+
------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 686034183 | | | |
+
------------------+-----------+--------------+------------------+-------------------+
- 配置slave
-
开启binlog vim /etc/my.cnf添加配置
12log_bin = mysql-bin
server_id = 1
-
启动slave执行sql
1CHANGE MASTER
TO
MASTER_HOST=
'master host'
, MASTER_USER=
'root'
, MASTER_PASSWORD=
'password'
,MASTER_LOG_FILE=
'mysql-bin.000001'
, MASTER_LOG_POS=686034183 ;
其中的MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=686034183;为上一步在master上执行SHOW MASTER STATUS;的结果
-
运行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting
for
master
to
send event
Master_Host: 123.57.207.198
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 686034183
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 686034113
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 686034183
Relay_Log_Space: 686034287
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: b4afeca0-1c33-11e5-856d-00163e002b08
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay:
NULL
Slave_SQL_Running_State: Slave has
read
all
relay log; waiting
for
the slave I/O thread
to
update
it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row
in
set
(0.00 sec)
其中Slave_IO_Running: Yes和Slave_SQL_Running: Yes则为正常,此时开始同步了
-
-
- master配置
相关文章
- Java Jedis操作Redis示例(四)——Redis和Mysql的结合方案演进
- mysql5.7主从(Master/Slave)同步配置
- Solr(搜索引擎服务)和MongoDB通过mongodb-connector进行数据同步的解决方案,以及遇到的各种坑的总结(针对solr-5.3.x版本),mongodb和solr实现实时增量索引
- MySQL 发生同步延迟时Seconds_Behind_Master还为0的原因
- 【ELK解决方案】ELK集群+RabbitMQ部署方案以及快速开发RabbitMQ生产者与消费者基础服务 ElasticSearch、head-master、Kibana环境搭建:https://www.cnblogs.com/weskynet/p/14853232.html 给ElasticSearch添加SQL插件和浏览器插件:https://www.cnblogs.com/weskynet/p/14864888.html 使用Logstash通过Rabbitmq接收Serilog日志到ES:https://www.cnblogs.com/weskynet/p/14952649.html 使用nssm工具将ES、Kibana、Logstash或者其他.bat文件部署为Windows后台服务的方法:https://www.cnblogs.com/weskynet/p/14961565.html
- Oracle和MySQL的高可用方案对比分析
- 基于MySQL数据库复制Master-Slave架构的分析
- mysql的master和slave同步方案
- MySql中 is Null段判断无效和IFNULL()失效的解决方案
- mysql同步error(Slave_IO_Running: )error connecting to master