MySQL 5.7基于GTID的主从复制环境搭建(一主一从)
| 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 | 
[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 :: ~]
#
[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]
#
(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;".
(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.
(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)
+---------------------------------------------------+------------------------------------------------------------------------------------------+
| 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)
(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)
MySQL 5.7基于GTID的主从复制环境搭建(一主一从)的更多相关文章
- mysql5.7.26 基于GTID的主从复制环境搭建
		
简单工作原理: (1)从库执行 change master to 语句,会立即将主库信息记录到master.info中 (2)从库执行 start slave语句,会立即生成IO_T和SQL_T (3 ...
 - mysql主从之基于gtid的主从复制
		
一 GITD介绍 1.1 gtid的含义 Global Transaction Identifier,全局事务标识 阿里云的rds目前已经使用gtid 基于gtid的主从复制原理 每个mysql数据库 ...
 - percona mysql server5.7基于gtid的主从复制
		
配置mysql基于gtid主从复制架构 一.二进制安装mysql [root@node5 data]# --Linux.x86_64.ssl101.tar.gz [root@node5 data]# ...
 - MySQL 5.7基于GTID的主从复制
		
since i've broken down the replication enviornment by "reset master;" yesterday.th ...
 - Mysql5.7实现主从复制、基于GTID的主从复制、并行复制
		
(一.主从复制) 一.mysql主从复制原理 mysql的默认复制方式是主从复制.Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制, ...
 - MySQL 5.7基于GTID复制的常见问题和修复步骤(二)
		
[问题二] 有一个集群(MySQL5.7.23)切换后复制slave报1236,其实是不小心在slave上执行了事务导致 Got fatal error 1236 from master when r ...
 - Ubuntu 基于Docker的TensorFlow 环境搭建
		
基于Docker的TensorFlow 环境搭建 基于(ubuntu 16.04LTS/ubuntu 14.04LTS) 一.docker环境安装 1)更新.安装依赖包 sudo apt-get up ...
 - EOS Dapp开发(1)-基于Docker的开发环境搭建
		
随着EOS主网的上线,相信基于EOS的Dapp开发会越来越多,查阅了很多资料相关的开发资料都不是很多,只能自己摸索,按照网上仅有的几篇教程,先git clonehttps://github.com/E ...
 - 基于Python的Appium环境搭建合集
		
自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...
 
随机推荐
- IAR6.1的工程迁移到IAR6.5不能用的解决方法
			
1.重命名过时的CMSIS头文件 "... \ CMSIS \ CM3 \ CoreSupport \ core_cm3.h 比如:core_cm3.h.old 2.启用CMSIS:项目- ...
 - 祝高二学弟学妹AK NOIp2018!!!!!!
			
 - supermarket SSM
			
1.数据库 2.整体空架构(jar包) 3.工程依赖 24节点 build节点 <properties> </project.build.sourceEncoding> < ...
 - 对fastdfs 文件清单进行检查,打印无效的文件
			
对fastdfs 文件清单进行检查,打印无效的文件2017年12月12日 18:37:18 守望dfdfdf 阅读数:281 标签: fastdfssftpmysql 更多个人分类: 工作 问题编辑版 ...
 - springboot整合mybatis+oracle
			
第一步 认识springboot :springboot是为了解决配置文件多,各个组件不统一的问题,它省去了很多配置文件,同时实现了spring产品的整合. 创建springboot项目:通过选择sp ...
 - Linux 两组信号对比
			
博客逐步迁移到,独立博客,原文地址 http://www.woniubi.cn/two_groups_signal_difference/ 之前看信号的时候,没有太注意不同信号的对比.今天再次看到的时 ...
 - win10 安装mysql zip 压缩包版
			
从官网下载zip https://www.mysql.com/downloads/ 解压 D:\devtool\mysql-5.7.17-winx64\ 将 D:\devtool\mysql--wi ...
 - DEEP LEARNING 大满贯课程表
			
Reinforcement Learning post by ISH GIRWAN Courses/Tutorials Deep Reinforcement Learning, Spring 2017 ...
 - 笨办法学Python(二十六)
			
习题 26: 恭喜你,现在可以考试了! 你已经差不多完成这本书的前半部分了,不过后半部分才是更有趣的.你将学到逻辑,并通过条件判断实现有用的功能. 在你继续学习之前,你有一道试题要做.这道试题很难,因 ...
 - Convolutional Neural Networks from deep learning (assignment 1 from week 1)
			
Convolutional Neural Networks https://www.coursera.org/learn/convolutional-neural-networks/home/welc ...