MySQL 5.7传统复制到GTID在线切换(一主一从)
Preface
Hostname | IP/Port | Identity | OS Version | MySQL Version | GTID Mode | Binlog Format |
zlm2 | 192.168.1.101/3306 | master | CentOS 7.0 | 5.7.21 | off | row |
zlm3 | 192.168.1.102/3306 | slave | CentOS 7.0 | 5.7.21 | off | row |
//Master
(root@localhost mysql3306.sock)[(none)]>show variables like 'gtid_mode';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode | OFF |
+---------------+-------+
row in set (0.01 sec //Slave
(root@localhost mysql3306.sock)[(none)]>show variables like 'gtid_mode';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode | OFF |
+---------------+-------+
row in set (0.00 sec)
[root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_insert.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --tables= --table-size= --mysql-storage-engine=innodb prepare
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Creating table 'sbtest1'...
Inserting records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
... [root@zlm2 :: ~/sysbench-1.0/src/lua]
#sysbench oltp_insert.lua --mysql-host=192.168.1.101 --mysql-port= --mysql-user=zlm --mysql-password=zlmzlm --mysql-db=sysbench --threads= --time= --report-interval= --rand-type=uniform run
sysbench 1.0. (using bundled LuaJIT 2.1.-beta2) Running the test with following options:
Number of threads:
Report intermediate results every second(s)
Initializing random number generator from current time Initializing worker threads... Threads started! [ 60s ] thds: tps: 1623.71 qps: 1623.71 (r/w/o: 0.00/1623.71/0.00) lat (ms,%): 2.97 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: tps: 1844.96 qps: 1844.96 (r/w/o: 0.00/1844.96/0.00) lat (ms,%): 2.61 err/s: 0.00 reconn/s: 0.00
[ 180s ] thds: tps: 1894.37 qps: 1894.37 (r/w/o: 0.00/1894.37/0.00) lat (ms,%): 2.61 err/s: 0.00 reconn/s: 0.00
... //Check the output of processlist.
(root@localhost mysql3306.sock)[(none)]>show processlist;
+----+------+------------+----------+-------------+------+---------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+------------+----------+-------------+------+---------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
| | root | localhost | NULL | Query | | starting | show processlist |
| | repl | zlm3: | NULL | Binlog Dump | | Master has sent all binlog to slave; waiting for more updates | NULL |
| | zlm | zlm2: | sysbench | Query | | update | INSERT INTO sbtest1 (id, k, c, pad) VALUES (, , '57837919367-24452778030-14591605115-8049012633 |
| | zlm | zlm2: | sysbench | Query | | update | INSERT INTO sbtest1 (id, k, c, pad) VALUES (, , '45087463438-93604980565-67881991526-9944080034 |
| | zlm | zlm2: | sysbench | Query | | update | INSERT INTO sbtest1 (id, k, c, pad) VALUES (, , '01822437471-94427682076-39418270545-9867829936 |
+----+------+------------+----------+-------------+------+---------------------------------------------------------------+------------------------------------------------------------------------------------------------------+
rows in set (0.00 sec)
(root@localhost mysql3306.sock)[(none)]>show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.101
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
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:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 1b7181ee-6eaf-11e8-998e-080027de0e0e
Master_Info_File: mysql.slave_master_info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: System lock
Master_Retry_Count:
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 //This means we are using the classic replication now.
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)
//Master
(root@localhost mysql3306.sock)[(none)]>set @@global.enforce_gtid_consistency=warn;
Query OK, rows affected (0.13 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.enforce_gtid_consistency;
+-----------------------------------+
| @@global.enforce_gtid_consistency |
+-----------------------------------+
| WARN |
+-----------------------------------+
row in set (0.06 sec) //Error log of master
--13T07::56.877416+: [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.
--13T07::15.748645+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 8825ms. The settings might not be optimal. (flushed= and evicted=, during the time.) //Slave
(root@localhost mysql3306.sock)[(none)]>set @@global.enforce_gtid_consistency=warn;
Query OK, rows affected (0.49 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.enforce_gtid_consistency;
+-----------------------------------+
| @@global.enforce_gtid_consistency |
+-----------------------------------+
| WARN |
+-----------------------------------+
row in set (1.35 sec) //Error log of slave
--13T07::02.556232+: [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN. //Make sure there's no warning messages on both master and slave.
//Master
(root@localhost mysql3306.sock)[(none)]>set @@global.enforce_gtid_consistency=on;
Query OK, rows affected (0.00 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.enforce_gtid_consistency;
+-----------------------------------+
| @@global.enforce_gtid_consistency |
+-----------------------------------+
| ON |
+-----------------------------------+
row in set (0.00 sec) //Slave
(root@localhost mysql3306.sock)[(none)]>set @@global.enforce_gtid_consistency=on;
Query OK, rows affected (0.03 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.enforce_gtid_consistency;
+-----------------------------------+
| @@global.enforce_gtid_consistency |
+-----------------------------------+
| ON |
+-----------------------------------+
row in set (0.00 sec)
//Master
(root@localhost mysql3306.sock)[(none)]>set @@globa.gtid_mode=off_permissive;
Query OK, rows affected (0.72 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.gtid_mode;
+--------------------+
| @@global.gtid_mode |
+--------------------+
| OFF_PERMISSIVE |
+--------------------+
row in set (0.01 sec) //Error log of master
--13T07::56.877416+: [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.
--13T07::15.748645+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 8825ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::38.472436+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 8569ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::03.886312+: [Note] Changed ENFORCE_GTID_CONSISTENCY from WARN to ON.
--13T07::04.137251+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 5067ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::39.586306+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 5394ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::38.441594+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 4927ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::19.070954+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 4539ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T07::20.930564+: [Note] Changed GTID_MODE from OFF to OFF_PERMISSIVE.
--13T07::36.490470+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 4602ms. The settings might not be optimal. (flushed= and evicted=, during the time.) //Slave
(root@localhost mysql3306.sock)[(none)]>set @@global.gtid_mode=off_permissive;
Query OK, rows affected (3.02 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.gtid_mode;
+--------------------+
| @@global.gtid_mode |
+--------------------+
| OFF_PERMISSIVE |
+--------------------+
row in set (0.00 sec) //Error log of slave
--13T07::02.556232+: [Note] Changed ENFORCE_GTID_CONSISTENCY from OFF to WARN.
--13T07::22.628014+: [Note] Changed ENFORCE_GTID_CONSISTENCY from WARN to ON.
--13T07::33.136288+: [Note] Aborted connection to db: 'unconnected' user: 'root' host: 'localhost' (Got timeout reading communication packets)
--13T07::27.360767+: [Note] Changed GTID_MODE from OFF to OFF_PERMISSIVE.
--13T07::39.972826+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 10489ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
//Master
(root@localhost mysql3306.sock)[(none)]>set @@global.gtid_mode=on_permissive;
Query OK, rows affected (3.26 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.gtid_mode;
+--------------------+
| @@global.gtid_mode |
+--------------------+
| ON_PERMISSIVE |
+--------------------+
row in set (0.00 sec) //Error log of master
--13T07::16.796632+: [Note] Changed GTID_MODE from OFF_PERMISSIVE to ON_PERMISSIVE.
--13T07::20.034425+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 4954ms. The settings might not be optimal. (flushed= and evicted=, during the time.) //Slave
(root@localhost mysql3306.sock)[(none)]>set @@global.gtid_mode=on_permissive;
Query OK, rows affected (2.22 sec) (root@localhost mysql3306.sock)[(none)]>select @@global.gtid_mode;
+--------------------+
| @@global.gtid_mode |
+--------------------+
| ON_PERMISSIVE |
+--------------------+
row in set (0.06 sec) //Error log of slave
--13T07::57.921081+: [Note] Changed GTID_MODE from OFF_PERMISSIVE to ON_PERMISSIVE.
--13T07::03.109628+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 5853ms. The settings might not be optimal. (flushed= and evicted=, during the time.) //I'm afraid it's better to execut "set gtid_mode=on_permissive;" on slave first for best practice even though sometimes it's not obliged to do that.
//Master
(root@localhost mysql3306.sock)[(none)]>show status like 'ongoing_anonymous_transaction_count';
+-------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------+-------+
| Ongoing_anonymous_transaction_count | |
+-------------------------------------+-------+
row in set (0.66 sec) //Slave
(root@localhost mysql3306.sock)[(none)]>show status like 'ongoing_anonymous_transaction_count';
+-------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------+-------+
| Ongoing_anonymous_transaction_count | |
+-------------------------------------+-------+
row in set (3.34 sec) //The value of 'ongoing_anonymous_transaction_count' become "0" what means there arn't non-gtid events in binlogs anymore.Therefore,we can do the last step,that is,to change the "gtid_mode" to "on".
//Master
(root@localhost mysql3306.sock)[(none)]>select @@global.gtid_mode;
+--------------------+
| @@global.gtid_mode |
+--------------------+
| ON |
+--------------------+
row in set (0.00 sec) //Error log of master
--13T08::59.853460+: [Note] Changed GTID_MODE from ON_PERMISSIVE to ON.
--13T08::01.804678+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 6035ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T08::56.202081+: [Note] Aborted connection to db: 'unconnected' user: 'repl' host: 'zlm3' (Failed on my_net_write()) //Slave
(root@localhost mysql3306.sock)[(none)]>set @@global.gtid_mode=on;
ERROR (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:
Current database: *** NONE *** //It's stuck here.Oh my!!! //Check the error log of slave see what has happened.
--13T08::49.070915+: [ERROR] Disk is full writing './relay-bin.000044' (Errcode: - No space left on device). Waiting for someone to free space...
--13T08::49.070948+: [ERROR] Retry in secs. Message reprinted in secs
--13T08::49.104353+: [ERROR] Disk is full writing '/data/mysql/mysql3306/logs/mysql-bin.000011' (Errcode: - No space left on device). Waiting for someone to free space...
--13T08::49.104382+: [ERROR] Retry in secs. Message reprinted in secs
--13T08::51.712891+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 4001ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
--13T08::00.346384+: [Note] InnoDB: page_cleaner: 1000ms intended loop took 7634ms. The settings might not be optimal. (flushed= and evicted=, during the time.) //It shows "[ERROR] Disk is full writing ... ".The test tables have been inserted too many data. [root@zlm3 :: ~]
#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root .4G .4G 20K % / //The root directory is full.
devtmpfs 488M 488M % /dev
tmpfs 497M 497M % /dev/shm
tmpfs 497M 6.6M 491M % /run
tmpfs 497M 497M % /sys/fs/cgroup
/dev/sda1 497M 118M 379M % /boot
none 87G 80G .1G % /vagrant //Unfortunately,the disk on salve has been writen fully.
//The output of "show salve status\G"
Last_IO_Errno:
Last_IO_Error: The replication receiver thread cannot start because the master has GTID_MODE = ON and this server has GTID_MODE = OFF //You cannot modify "gtid_mode" to "on" directly.
(root@localhost mysql3306.sock)[(none)]>set @@global.gtid_mode=on;
ERROR (HY000): The value of @@GLOBAL.GTID_MODE can only be changed one step at a time: OFF <-> OFF_PERMISSIVE <-> ON_PERMISSIVE <-> ON. Also note that this value must be stepped up or down simultaneously on all servers. See the Manual for instructions.
- GTID replication is the best practice in MySQL replicaiton now,especially in 5.7 version above.More and more new good features are relies on GTID,such as "Group Replication","Group Commit","Parallel Replication",etc.
- We'd better replace all the classic replication to GTID replication in our product environment in order to get more benifits and work efficiently.
- Chang classic replicaiton to GTID replicaiton online should follow the order of "off -> off_permissive -> on_permissive -> on" and execute them on both master and slaves.
- Notice that change online is only support on MySQL 5.7.6 and above.
MySQL 5.7传统复制到GTID在线切换(一主一从)的更多相关文章
- MySQL 5.7 传统复制到GTID在线切换
来源:http://wubx.net/ 联系方式: wubingxi#163.com 转载请注明作/译者和出处,并且不能用于商业用途,违者必究. 前题: 要求MySQL 5.7.6及以后版本. 所有组 ...
- (5.12)mysql高可用系列——复制中的在线切换GTID模式/增加节点/删除节点
目录 [0]需求 前提,已经假设好基于传统异步复制的主库和从库1. [0.1]传统异步切换成基于GTID的无损模式 [0.2]增加特殊要求的从库 [1]操作环境 [2]构建 复制->半同步复制 ...
- MySQL 5.7--多源复制(非GTID模式)
==================================================== 在MYSQL5.7版本中引入多源复制,一个从库允许复制多个主库的数据,每个主库被配置为一个单独 ...
- MySQL5.7不停业务将传统复制变更为GTID复制
由于GTID的优势,我们需要将传统基于file-pos的复制更改为基于GTID的复制,如何在线变更成为我们关心的一个点,如下为具体的方法: 目前我们有一个传统复制下的M-S结构: port 330 ...
- MySQL的GTID复制与传统复制的相互转换
主库:192.168.225.128:3307从库1:192.168.225.129:3307 Gtid作为5.6版本以来的杀手级特性,却因为不支持拓扑结构内开关而饱受诟病.如果你需要从未开启GTID ...
- 在线建立或重做mysql主从复制架构方法(传统模式和GTID模式)【转】
mysql主从复制架构,是mysql数据库主要特色之一,绝大多数公司都有用到. 而GTID模式是基于事务的复制模式的意思,发展到现在也是越来越多人用. 以前很多文章,介绍搭建mysql主从复制架构,是 ...
- MySQL的GTID复制与传统复制的相互切换
MySQL的GTID复制与传统复制的相互转换 1. GTID复制转换成传统复制 1.1 环境准备 1.2 停止slave 1.3 查看当前主从状态 1.4 change master 1.5 启动主从 ...
- 与MySQL传统复制相比,GTID有哪些独特的复制姿势?
与MySQL传统复制相比,GTID有哪些独特的复制姿势? http://mp.weixin.qq.com/s/IF1Pld-wGW0q2NiBjMXwfg 陈华军,苏宁云商IT总部资深技术经理,从事数 ...
- mysql同步复制异常的常见操作-传统复制方式
mysql同步复制异常的常见操作-传统复制方式 一.传统复制方式是基于非gtid的,常见的错误有1032和1062 1032是主键冲突,1062是从库中没有找到对应的记录. 可以查看出现错误的binl ...
随机推荐
- org.apache.subversion.javahl.ClientException: Working copy is not up-to-date
之前因为将项目中的一个文件删除了,然后添加了新的文件,svn提交的时候报错. 提示:Working copy is not up-to-date 解决办法:对应的项目上右键然后选择team,然后选择u ...
- Quartz使用(1) - 初识quartz
1. 背景 由于最新的工作项目中,需要使用quartz框架,以完成相关的任务的定时执行.经过两周的调研与使用,本系列博客会参考官网及网上相关博客,结合工作项目中的使用,详细介绍quartz的各个方面. ...
- 自定义Qt组件-通讯模块(P2)
1. 抽象协议AbstractProtocol 抽象协议AbstractProtocol定义CommManager与协议之间的接口.AbstractProtocol中的一些属性(如enabled)用 ...
- .NET面试题5
常见面试题目: 1. const和readonly有什么区别? 2. 哪些类型可以定义为常量?常量const有什么风险? 3. 字段与属性有什么异同? 4. 静态成员和非静态成员的区别? 5. 自动属 ...
- Win2D 官方文章系列翻译 - 与 Direct2D 互操作
本文为个人博客备份文章,原文地址: http://validvoid.net/win2d-interop-with-direct2d/ Win2D 作为 Direct2D 的上层实现,支持与其进行双向 ...
- intellijidea课程 intellijidea神器使用技巧 3-1 列操作
Ctrl shift 右箭头 ==> 选中右边单词 ctrl shift alt L ==> 选中所有相同的字符 Ctrl alt L ==> 格式化
- F12 chrome开发者工具
1.Network详解篇 : https://blog.csdn.net/qq_39208536/article/details/79304148 2.sources: js调试篇 http://b ...
- oracle多表查询和子查询练习
--1.列出至少有三个员工的所有部门和部门信息. SELECT D.DEPTNO, D.DNAME, D.LOC, T.COUNTS FROM DEPT D, (SELECT DEPTNO, CO ...
- 转:用AutoCAD 系统变量编程
Autocad的系统变量, 我们可以通过如下得到: Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable(/*MSG0* ...
- Row_number() OVER(PARTITION BY xxx ORDER BY XXX)分组排序
--//创建一个信息表 ,) ,),st_name ),class ),score ,)) --//插入测试数据============start=================== insert ...