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环境搭建合集
自动化一直是测试圈中的热聊,也是大家追求的技术方向.在测试中,往往回归测试也是测试人员的“痛点”.对于迭代慢.变更少的功能,就能用上自动化来替代人工回归,减轻工作量. 问题 在分享环境搭建之前,先抛出 ...
随机推荐
- 使用Nginx、Keepalived构建文艺负载均衡
面对网站服务器端负载增大的问题,是"拿15万¥买一台服务器"来解决,还是靠"加三倍服务器"来解决?还是用其它一些办法? 对于一个访问量日益增加的网站架构而言,从 ...
- DEDE列表页和内容页调用顶级栏目ID的方法
dede模板中添加顶级栏目id的方法总结,使用dede顶级栏目id可以实现很多功能.比如,在每个列表页调用不同的栏目图片(同一顶级栏目调用相同的图片),如果我们做N个栏目就意味着要做N个列表页模板,显 ...
- anaular js loadding效果
以前用的jquery的时候,用ajax实现,比较好弄,下面是angularjs的方式: //body下面增加div <div data-loading></div> //dir ...
- 对于ESP、EBP寄存器的理解
原文:http://blog.csdn.net/yeruby/article/details/39780943 esp是栈指针,是cpu机制决定的,push.pop指令会自动调整esp的值: ebp只 ...
- as3.0 动态文本属性大全
var my_fmt = new TextFormat();//常用样式 my_fmt.align = "center"; my_fmt.blockIndent = 50; //区 ...
- vue 2.6 更新变动
[原文链接] Slots:新语法,性能改进为3.0做准备改用 v-slot 指令 //默认插槽 <baz v-slot ="baz"> {{baz}} </ ba ...
- 基于 MUI 构建一个具有 90 +页面的APP应用
前言 mui是一款接近原生App体验的前端框架,只需要掌握前端技术就可以开发APP应用,官方有提供功能比较全面的demo版本, 但在实战中总会遇到一些不可避免但坑,对于没有接触过mui的开发者,难免会 ...
- android studio gradle统一管理版本
创建config.gradle ext { android = [ compileSdkVersion : 26, buildToolsVersion : "26.0.2", mi ...
- Struts2_简单数据验证
在Action 中添加 FieldError if(name == null || !name.equals("admin")){ this.addFieldError(" ...
- PHP switch分支语句中省略break后还会执行其他case的原因分析
请分析以下PHP代码的输出结果: $a= 'dog'; switch($a) { case 'cat': echo "\$a is cat"; case 'dog': echo & ...