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环境搭建合集
自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...
随机推荐
- git跟svn 服务端对比
Git已经火了很久,简单的使用也没有问题,但有几个问题一直以来都没有搞清楚:git跟svn有哪些异同,两者相互的优劣是什么,git的分布式怎么理解,为什么有离线提交,,,自己动手,分别看一下服务端跟客 ...
- JS arguments转array
JS arguments转array? Array.prototype.slice.call(arguments)
- linux工具:快速返回某级父目录--bd
当我们在linux服务器上切换父目录时,通常使用cd ../../,有几级目录就输入几次"../",如果目录嵌套的过深,就会有点晕菜...因此,本次介绍的这款工具,可以快速的返回指 ...
- Java反射破坏单例模式
今天电话面试的时候问到了,Google了一下 原出处: http://blog.csdn.net/lws332969674/article/details/8125893 一. Java中的反射技术可 ...
- Dubbo分布式日志追踪
使用dubbo分布式框架进行微服务的开发,一个大系统往往会被拆分成很多不同的子系统,并且子系统还会部署多台机器,当其中一个系统出问题了,查看日志十分麻烦. 所以需要一个固定的流程ID和机器ip地址等来 ...
- 浏览器缓存介绍之sessionStorage、localStorage、Cookie
Cookie Cookie 是小甜饼的意思.顾名思义,cookie 确实非常小,它的大小限制为4KB左右,是网景公司的前雇员 Lou Montulli 在1993年3月的发明.它的主要用途有保存登录信 ...
- 《Head First 设计模式》总结
复合模式——模式的模式 MVC(模型-视图-控制器):是由数个设计模式结合起来的模式. 戴着模式的有色眼镜看MVC: 模型利用观察者模式让控制器和视图可以随最新的状态改变而更新. 模型对视图和控制器一 ...
- C#中关于静态与非静态的一个疑问
关于静态方法.变量和非静态方法.变量的区别,园里的大神早就有了许多详细的总结,个人觉得静态方法.变量与非静态方法.变量的区别可以总结为以下两句话: 静态的是属于类的 非静态是属于对象的 就是说调用静态 ...
- Redis整理第二波(启动、命令)
启动 配置数据库数量: Redis默认开启16个数据库,不能像mysql自定义数据库名称,只能是数值,不能修改. 配置内存大小: 会生成一个和内存大小一样的文件. maxmemory 200mb #在 ...
- atom markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module
atom编辑器markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module. You have to set th ...