Preface
 
    As wel all know,replication base on GTID with row format of binary log is comprehensive used nowadays,especially in MySQL 5.7 version above.I'm going to demonstrate a simplest way to implement a replacation within two servers.
 
Framework
 
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 on row
zlm3 192.168.1.102/3306 slave CentOS 7.0 5.7.21 on row
 
Procedure
 
Generate a new backup by mysqldump and send it to slave host.
 [root@zlm2 :: ~]
#mysqldump -S /tmp/mysql3306.sock -p -A --single-transaction --master-data= > db3306_`date +%Y%m%d`.sql
Enter password:
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. [root@zlm2 :: ~]
#ls -l|grep *.sql [root@zlm2 :: ~]
#ls -l|grep db3306
-rw-r--r-- root root Jul : db3306_20180710.sql [root@zlm2 :: ~]
#scp db3306_20180710.sql 192.168.1.102:/data
root@192.168.1.102's password:
db3306_20180710.sql % 7161KB .0MB/s : [root@zlm2 :: ~]
#
Import the backup on slave host with mysql client tool.
 [root@zlm3 :: ~]
#cd /data [root@zlm3 :: /data]
#ls -l
total
drwxr-xr-x mysql mysql Jun : backup
-rw-r--r-- root root Jul : db3306_20180710.sql
drwxr-xr-x mysql mysql Apr : mysql [root@zlm3 :: /data]
#mysql -S /tmp/mysql3306.sock -p < db3306_20180710.sql
Enter password:
ERROR (HY000) at line : @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty. //We cannot set global.gtid_purged while global.gtid_executed isn't empty before MySQL 8.0.
//The only way is executing "reset master;" on slave. [root@zlm3 :: /data]
#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (root@localhost mysql3306.sock)[(none)]>show master status;
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------+
| mysql-bin. | | | | 1b7181ee-6eaf-11e8-998e-080027de0e0e:-,
5c77c31b-4add-11e8-81e2-080027de0e0e:-,
ed142e35-6ed1-11e8-86c6-080027de0e0e:- |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------------------------------------------------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]>reset master; //After execute it,binlogs on slave will be deleted.
Query OK, rows affected (0.02 sec) (root@localhost mysql3306.sock)[(none)]>show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin. | | | | |
+------------------+----------+--------------+------------------+-------------------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]>exit
Bye [root@zlm3 :: /data]
#mysql -S /tmp/mysql3306.sock -p < db3306_20180710.sql //Import backed data again.
Enter password: [root@zlm3 :: /data]
#
Create replication user 'replica' with password 'replica' on master host.
 (root@localhost mysql3306.sock)[(none)]>create user replica@'192.168.1.%' identified by 'replica';
Query OK, rows affected (0.01 sec) (root@localhost mysql3306.sock)[(none)]>grant replication slave on *.* to replica@'192.168.1.%';
Query OK, rows affected (0.00 sec) //You can also create the replication user before generating backup.
//Take care of the operation of flushing privileges if there're any problem after executing "start salve;".
Set "change master ... " on slave host.
 (root@localhost mysql3306.sock)[(none)]>change master to \
-> master_host='192.168.1.101', \
-> master_port=, \
-> master_user='replica', \
-> master_password='replica', \
-> master_auto_position=; //As we are using GTID mode to implement replication,this is indispensable.
Query OK, rows affected, warnings (0.02 sec) //If you've forgotten the syntax,you can type "help change master to" to know details. (root@localhost mysql3306.sock)[(none)]>show warnings;
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Note | | Sending passwords in plain text without SSL/TLS is extremely insecure. |
| Note | | Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information. |
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
rows in set (0.00 sec) //Ignore these above warnings. (root@localhost mysql3306.sock)[(none)]>show slave status\G
*************************** . row ***************************
Slave_IO_State:
Master_Host: 192.168.1.101
Master_User: replica
Master_Port:
Connect_Retry:
Master_Log_File:
Read_Master_Log_Pos:
Relay_Log_File: relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: No
Slave_SQL_Running: No
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: NULL
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:
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: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-,
ed142e35-6ed1-11e8-86c6-080027de0e0e:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec) //The output shows the details about master info.
Execute "start slave;" on slave host.
 (root@localhost mysql3306.sock)[(none)]>start slave;
Query OK, rows affected (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: replica
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 //IO Thread is working normally.
Slave_SQL_Running: Yes //SQL Thread is working normally.
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: Slave has read all relay log; waiting for more updates
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-
Executed_Gtid_Set: 1b7181ee-6eaf-11e8-998e-080027de0e0e:-,
ed142e35-6ed1-11e8-86c6-080027de0e0e:-
Auto_Position:
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
row in set (0.00 sec)
    Okay,we are well-off to get a replication architecture now.Is that simple?
 
Variables relevant to GTID on master host.
 +---------------------------------------------------+------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------------------------------------------+------------------------------------------------------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| group_replication_allow_local_disjoint_gtids_join | OFF |
| group_replication_gtid_assignment_block_size | |
| gtid_executed_compression_period | |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | 1b7181ee-6eaf-11e8-998e-080027de0e0e:-,
ed142e35-6ed1-11e8-86c6-080027de0e0e:- |
| session_track_gtids | OFF |
+---------------------------------------------------+------------------------------------------------------------------------------------------+
rows in set (0.00 sec)
Variables relevant to GTID on master host.
 (root@localhost mysql3306.sock)[(none)]>show variables like '%gtid%';
+---------------------------------------------------+------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------------------------------------------+------------------------------------------------------------------------------------------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| group_replication_allow_local_disjoint_gtids_join | OFF |
| group_replication_gtid_assignment_block_size | |
| gtid_executed_compression_period | |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | 1b7181ee-6eaf-11e8-998e-080027de0e0e:-,
ed142e35-6ed1-11e8-86c6-080027de0e0e:- |
| session_track_gtids | OFF |
+---------------------------------------------------+------------------------------------------------------------------------------------------+
rows in set (0.00 sec)
    We find out that they're almost the same except the variable of "gtid_purged" on slave is larger than it on master host.It's normal.The value will continuously increase while binlogs(actually relay logs) are purged after applying them on slave from time to time if only sql_thread is running.
 

MySQL 5.7基于GTID的主从复制环境搭建(一主一从)的更多相关文章

  1. mysql5.7.26 基于GTID的主从复制环境搭建

    简单工作原理: (1)从库执行 change master to 语句,会立即将主库信息记录到master.info中 (2)从库执行 start slave语句,会立即生成IO_T和SQL_T (3 ...

  2. mysql主从之基于gtid的主从复制

    一 GITD介绍 1.1 gtid的含义 Global Transaction Identifier,全局事务标识 阿里云的rds目前已经使用gtid 基于gtid的主从复制原理 每个mysql数据库 ...

  3. percona mysql server5.7基于gtid的主从复制

    配置mysql基于gtid主从复制架构 一.二进制安装mysql [root@node5 data]# --Linux.x86_64.ssl101.tar.gz [root@node5 data]# ...

  4. MySQL 5.7基于GTID的主从复制

            since i've broken down the replication enviornment by "reset master;" yesterday.th ...

  5. Mysql5.7实现主从复制、基于GTID的主从复制、并行复制

    (一.主从复制) 一.mysql主从复制原理    mysql的默认复制方式是主从复制.Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制, ...

  6. MySQL 5.7基于GTID复制的常见问题和修复步骤(二)

    [问题二] 有一个集群(MySQL5.7.23)切换后复制slave报1236,其实是不小心在slave上执行了事务导致 Got fatal error 1236 from master when r ...

  7. Ubuntu 基于Docker的TensorFlow 环境搭建

    基于Docker的TensorFlow 环境搭建 基于(ubuntu 16.04LTS/ubuntu 14.04LTS) 一.docker环境安装 1)更新.安装依赖包 sudo apt-get up ...

  8. EOS Dapp开发(1)-基于Docker的开发环境搭建

    随着EOS主网的上线,相信基于EOS的Dapp开发会越来越多,查阅了很多资料相关的开发资料都不是很多,只能自己摸索,按照网上仅有的几篇教程,先git clonehttps://github.com/E ...

  9. 基于Python的Appium环境搭建合集

    自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...

随机推荐

  1. CSS零碎知识点

    一.zoom:1 IE专有属性 可以设置或检索对象的缩放比例 触发IE的layout属性 清除浮动:overflow:hidden;zoom:1; 但要尽量比较使用这种方法 zoom:1;可以拯救IE ...

  2. JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题

    1. getComputedStyle()  方法获取到的是经过计算机/浏览器计算后的样式 getComputedStyle($("#div")).width; 兼容性:IE6 7 ...

  3. 微信小程序 列表渲染 wx:for

    wx:for控制属性绑定一个数组,即可使用数组中各项的数据重复渲染该组件. wx:for-item指定数组当前元素,或当前项的变量名wx:for-index 指定数组当前下标的变量名 <view ...

  4. JetBrains IDE激活

    License server(服务器地址为http://idea.iteblog.com/key.php) Active Code:生成网址:http://idea.iteblog.com/

  5. ping过程详解

    原出处:http://wanicy.blog.51cto.com/509018/335207/ PS:这里只是给出了ping ip地址的例子,没有给出ping域名的例子. ping 域名还有域名转换成 ...

  6. Visual Studio Code 入门教程

    Extensible and customizable.(可扩展的和可定制的,这是我喜欢它的原因) Want even more features? Install extensions to add ...

  7. 使用ionic cordova build android --release --prod命令打包报错解决方法

    使用ionic cordova build android --release --prod命令打包报有如下错误及解决方法 只要把以下内容添加到build-extras.gradle或(build** ...

  8. Struts1.x 用户登录模块的实现

    页面验证部分: <%@ page language="java" contentType="text/html; charset=UTF-8" pageE ...

  9. Oracle11g 卸载教程图解

    1:停掉所有Oracle相关的服务 1.1打开服务方式如下: 1.1.1:右击“计算机”–>管理–>服务和应用程序–>服务 1.1.2:开始–>输入“服务”后点击搜索–> ...

  10. SQL中的聚合函数

    聚合函数是对一组值执行计算并返回单一的值的函数,它经常与SELECT语句的GROUP BY子句一同使用,SQL SERVER 中具体的聚合函数如下:1. AVG 返回指定组中的平均值,空值被忽略. 例 ...