前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL5.7配置基于GTID的复制及GTID回退到传统模式的方法

MySQL5.7配置基于GTID的复制及GTID回退到传统模式的方法

作者头像
保持热爱奔赴山海
发布2019-09-18 15:12:03
6780
发布2019-09-18 15:12:03
举报

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.sql

scp /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

记录下当前复制到哪里了,如下图红色部分:

wKioL1ihuimyWmntAAAndWA_VBM825.png
wKioL1ihuimyWmntAAAndWA_VBM825.png

> 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复制的转成传统模式了。

wKioL1ihuinAQsQXAABEWafOVnw584.png
wKioL1ihuinAQsQXAABEWafOVnw584.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-02-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档