MySQL5.7配置基于GTID的复制及GTID回退到传统模式的方法
2017-02-13 21:57
726 查看
MySQL5.7下配置GTID复制的方法:环境:
CentOS6.8X86_64
MySQL Community 5.7.17
node1:192.168.2.171 主库
node2:192.168.2.172 从库
修改主库和从库的配置文件,加入红色部分的配置项:
主库:
[mysqld]
log-bin=mysql-bin
binlog_format= ROW
gtid-mode = ON
enforce_gtid_consistency = ON
master-info-repository=TABLE
relay-log-info-repository=TABLE
从库:
[mysqld]
log-bin=mysql-bin
binlog_format= ROW
log_slave_updates = ON
gtid-mode = ON
enforce_gtid_consistency = ON
master-info-repository=TABLE
relay-log-info-repository=TABLE
重启主库和从库,使上面的配置生效。
然后在node1上导出全量的数据并传到node2:
mysqldump -uroot -proot -q--single-transaction -A > /root/all.sqlscp /root/all.sql root@192.168.2.172:/root
在node2上导入: mysql -uroot -proot < /root/all.sql
然后,还要在node1的主库创建个复制权限的账号:
> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluser'@'192.168.2.%' IDENTIFIED BY 'Abcd@1234';
在slave上配置change master to指向(如下6行代码):
> change master to
master_HOST='192.168.2.171',
master_PORT=3306,
master_USER='repluser',
master_PASSWORD='Abcd@1234',
master_AUTO_POSITION=1;
> start slave;
> show slave status\G 结果如下:
***************************1. row ***************************
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.2.171
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql.000006
Read_Master_Log_Pos: 786
Relay_Log_File:node2-relay-bin.000002
Relay_Log_Pos: 991
Relay_Master_Log_File: mysql.000006
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: 786
Relay_Log_Space: 1198
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:101
Master_UUID:e2deedc8-ed36-11e6-b826-000c29f17302
Master_Info_File:mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has readall relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:e2deedc8-ed36-11e6-b826-000c29f17302:1-3
Executed_Gtid_Set:e2deedc8-ed36-11e6-b826-000c29f17302:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
这样,我们的基于GTID的复制就配置完成了。
GTID复制转成传统模式的方法:
如果之前启用过了GTID,那么就不能不能再使用传统的change master to的方式了,会报错,如下:
ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS,RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION isactive.
要转换成传统模式,需要在my.cnf里面注释掉下面2行:
gtid-mode=ON
enforce_gtid_consistency = ON
然后重启MySQL。
解决方法:
> stop slave;
> show slave status\G
记录下当前复制到哪里了,如下图红色部分:
> change master to MASTER_AUTO_POSITION=0; # 设置为0关闭这个选项,这个选项是GTID复制才用到的。
> CHANGE MASTER TO
MASTER_HOST = '192.168.2.171',
MASTER_USER='repluser',
MASTER_PASSWORD='Abcd@1234',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql.000006',
MASTER_LOG_POS=786,
MASTER_CONNECT_RETRY=10;
> start slave;
> show slave status\G 验证下是否IO/SQL都是YES状态。如下图,我们已经将GTID复制的转成传统模式了。
CentOS6.8X86_64
MySQL Community 5.7.17
node1:192.168.2.171 主库
node2:192.168.2.172 从库
修改主库和从库的配置文件,加入红色部分的配置项:
主库:
[mysqld]
log-bin=mysql-bin
binlog_format= ROW
gtid-mode = ON
enforce_gtid_consistency = ON
master-info-repository=TABLE
relay-log-info-repository=TABLE
从库:
[mysqld]
log-bin=mysql-bin
binlog_format= ROW
log_slave_updates = ON
gtid-mode = ON
enforce_gtid_consistency = ON
master-info-repository=TABLE
relay-log-info-repository=TABLE
重启主库和从库,使上面的配置生效。
然后在node1上导出全量的数据并传到node2:
mysqldump -uroot -proot -q--single-transaction -A > /root/all.sqlscp /root/all.sql root@192.168.2.172:/root
在node2上导入: mysql -uroot -proot < /root/all.sql
然后,还要在node1的主库创建个复制权限的账号:
> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repluser'@'192.168.2.%' IDENTIFIED BY 'Abcd@1234';
在slave上配置change master to指向(如下6行代码):
> change master to
master_HOST='192.168.2.171',
master_PORT=3306,
master_USER='repluser',
master_PASSWORD='Abcd@1234',
master_AUTO_POSITION=1;
> start slave;
> show slave status\G 结果如下:
***************************1. row ***************************
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.2.171
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql.000006
Read_Master_Log_Pos: 786
Relay_Log_File:node2-relay-bin.000002
Relay_Log_Pos: 991
Relay_Master_Log_File: mysql.000006
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: 786
Relay_Log_Space: 1198
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:101
Master_UUID:e2deedc8-ed36-11e6-b826-000c29f17302
Master_Info_File:mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has readall relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:e2deedc8-ed36-11e6-b826-000c29f17302:1-3
Executed_Gtid_Set:e2deedc8-ed36-11e6-b826-000c29f17302:1-3
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
这样,我们的基于GTID的复制就配置完成了。
GTID复制转成传统模式的方法:
如果之前启用过了GTID,那么就不能不能再使用传统的change master to的方式了,会报错,如下:
ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS,RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION isactive.
要转换成传统模式,需要在my.cnf里面注释掉下面2行:
gtid-mode=ON
enforce_gtid_consistency = ON
然后重启MySQL。
解决方法:
> stop slave;
> show slave status\G
记录下当前复制到哪里了,如下图红色部分:
> change master to MASTER_AUTO_POSITION=0; # 设置为0关闭这个选项,这个选项是GTID复制才用到的。
> CHANGE MASTER TO
MASTER_HOST = '192.168.2.171',
MASTER_USER='repluser',
MASTER_PASSWORD='Abcd@1234',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql.000006',
MASTER_LOG_POS=786,
MASTER_CONNECT_RETRY=10;
> start slave;
> show slave status\G 验证下是否IO/SQL都是YES状态。如下图,我们已经将GTID复制的转成传统模式了。
相关文章推荐
- 在线建立或重做mysql主从复制架构方法(传统模式和GTID模式)【转】
- 在线建立或重做mysql主从复制架构方法(传统模式和GTID模式)
- MySQL5.6 GTID模式,同步复制报错不能跳过解决方法
- 企业级-Mysql双主互备高可用负载均衡架构(基于GTID主从复制模式)
- MySQL5.7不停业务将传统复制变更为GTID复制的实例
- Mysql 5.7从节点配置多线程主从复制的方法详解
- MySQL5.6基于GTID的主从复制配置
- Mysql 5.6 基于GTID的主从复制及使用Amoeba配置读写分离
- mysql 5.6复制新特性下主从复制配置[基于GTID]
- MySQL 5.7 传统复制到GTID在线切换
- MySQL 5.7 传统复制到GTID在线切换
- 企业级-Mysql双主互备高可用负载均衡架构(基于GTID主从复制模式)
- mysql主从复制配置(基于GTID)
- mysql 5.7传统复制到gtid复制的在线切换
- MySQL 5.6配置GTID复制模式
- MySQL5.7 基于GTID的多源复制
- MySQL5.6 GTID模式 同步复制跳过报错解决方法
- rhel6系统中,mysql 5.6复制新特性下主从复制配置[基于GTID]
- 基于GTID的MySQL多源复制配置
- MySQL 5.7 基于GTID的半同步复制