mysql3308_mysql 5.7.16多源复制
演示一下在MySQL下搭建多主一从的过程。
实验环境:
192.168.24.129:3306
192.168.24.129:3307
192.168.24.129:3308
主库操作
导出数据
分别在3306和3307上导出需要的数据库。
3306:
登录数据库:
[root@localhost 3306]# mysql -uroot -poldboy123 -S /tmp/mysql3306.sock
锁表:
mysql> flush tables with read lock;
状态点:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
另开窗口开始导数据:
[root@localhost tmp]# mysqldump -uroot -poldboy123 -S /tmp/mysql3306.sock -F -R -x --master-data=2 -A --events|gzip >/tmp/dockerwy.sql.gz
在此查看状态点两个要保持一致,否则表没有锁住
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
解锁表:
mysql> unlock tables;
3307:
登录3307数据库:
[root@localhost 3307]# mysql -uroot -poldboy123 -S /tmp/mysql3307.sock
锁表:
mysql>flush tables with read lock;
查看状态点:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
另开窗口导数据:
[root@localhost 3307]# mysqldump -uroot -poldboy123 -S /tmp/mysql3307.sock -F -R -x --master-data=2 -A --events|gzip >/tmp/dockerwy_2.sql.gz
从新查看状态点:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File| Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000008 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
解锁表:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
建立授权账号
分别在3306和3307上面建立授权账号
3306:
mysql> grant replication slave on *.* to 'backup'@'192.168.24.129' identified by 'backup';
3307:
mysql> grant replication slave on *.* to 'backup'@'192.168.24.129' identified by 'backup';
从库操作
修改从库存储方式
修改3308的master-info和relay-info方式,从文件存储改为表存储。
编辑配置文件
[root@localhost 3308]# vim my.cnf
在[mysqld]模块下添加如下两行
master_info_repository=TABLE
relay_log_info_repository=TABLE
重启3308数据库:
[root@localhost 3308]# /data/3308/mysqld restart
重启之后我们可以登录数据库查看;
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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.
mysql> show variables like 'relay_log_info_repository';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| relay_log_info_repository | TABLE |
+---------------------------+-------+
1 row in set (0.01 sec)
mysql> show variables like 'master_info_repository';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| master_info_repository | TABLE |
+------------------------+-------+
1 row in set (0.01 sec)
导入数据
导入3306的数据:
[root@localhost 3308]# gzip -d /tmp/dockerwy.sql.gz
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock < /tmp/dockerwy.sql.
导入3307的数据:
[root@localhost 3308]# gzip -d /tmp/dockerwy_2.sql.gz
[root@localhost 3308]# mysql -uroot -poldboy123 -S /tmp/mysql3308.sock < /tmp/dockerwy_2.sql
执行change master to
登录slave进行同步操作,分别change master两台服务器,后面以for channel ‘channel_name’区分
mysql> change master to master_host='192.168.24.129',master_user='backup',master_port=3306,master_password='backup',master_log_file='mysql-bin.000006',master_log_pos=154 for channel 'master_1';
Query OK, 0 rows affected, 2 warnings (0.07 sec)
mysql> change master to master_host='192.168.24.129',master_user='backup',master_port=3307,master_password='backup',master_log_file='mysql-bin.000007',master_log_pos=154 for channel 'master_2';
Query OK, 0 rows affected, 2 warnings (0.04 sec)
启动slave操作
可以通过start slave的方式去启动所有的复制,也可以通过单个复制源的方式,下面介绍单个复制的的启动演示
mysql> start slave for channel 'master_1';
Query OK, 0 rows affected (0.01 sec)
mysql> start slave for channel 'master_2';
Query OK, 0 rows affected (0.02 sec)
查看同步状态
正常启动后,可以查看同步的状态,执行show slave status for channel ‘channel_name\G’查看复制源master_1的同步状态;
mysql> show slave status for channel 'master_1'\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.24.129
Master_User: backup
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin-master_1.000006
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000008
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 634
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 129
Master_UUID: df233252-afd5-11e6-8070-000c2962d708
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
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
Replicate_Rewrite_DB:
Channel_Name: master_1
Master_TLS_Version:
1 row in set (0.00 sec)
查看master_2的同步状态
mysql> mysql> show slave status for channel 'master_2'\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.24.129
Master_User: backup
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin-master_2.000004
Relay_Log_Pos: 367
Relay_Master_Log_File: mysql-bin.000008
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 634
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 130
Master_UUID: 49bf20e1-afe2-11e6-aef5-000c2962d708
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
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
Replicate_Rewrite_DB:
Channel_Name: master_2
Master_TLS_Version:
1 row in set (0.00 sec)
mysql3308_mysql 5.7.16多源复制相关推荐
- Ubuntu 16.04源码编译安装Apache 2.4.25教程
这篇文章主要为大家详细介绍了Ubuntu 16.04源码编译安装Apache 2.4.25,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本文为大家介绍了Ubuntu 16.04源码编译安装Apa ...
- mysql5.7组复制多主一从搭建_MySql5.7-多源复制(多主单从)
1.1.主库配置 my.cnf #确保唯一 server-id=1 #作为Master要开启binlog log-bin=mysql-bin #binlog format有三种形式:Statement ...
- mysql多源复制 知乎_MySQL多主一从(多源复制)同步配置
>多主一从,也称为多源复制,数据流向.这是小编的服务器部署的一次小尝试,实际工作中还没遇到过 形式 主库1 -> 从库s 主库2 -> 从库s 主库n -> 从库s 应用场景 ...
- mysql master slave 灾备技术_MySQL灾备恢复在线主从复制变成主主复制及多源复制【转】...
生产主主复制(AB),和灾备主从复制(B--->C).当生产出现问题时,数据写入切换到灾备数据库,待生产恢复后,将灾备回写到生产.步骤如下: 1.灾备与生产其中一台建立主主复制,这样生产的那台就 ...
- Anaconda Python3.6 OpenCV4.1.0 Ubuntu 16.04源码编译
Anaconda Python3.6 OpenCV4.1.0 Ubuntu 16.04源码编译 转载于:https://blog.csdn.net/phdsky/article/details/782 ...
- Mysql多源复制半同步_MySQL多源复制搭建
1.1 实验概要 1.1.1 实验假设 本实验假设已经完成操作系统和MySQL安装部署. 1.1.2 实验目的 MySQL5.7的多源复制技术搭建部署,然后简单测试. 1.1.3 环境信 ...
- MySQL案例-多源复制引起的内存泄漏
-------------------------------------------------------------------------------------------------正文- ...
- mysql 5.7配置多线程复制,MySQL5.7复制功能实战,基于事务的复制,多源复制和多线程复制配置...
这篇是幕课网-MySQL5.7复制功能实战视频教程的学习笔记.http://www.imooc.com/learn/589 第1章 MySQL复制基础 MySQL是异步复制 采取针对特定用户的读写分离 ...
- MySQL多源复制【转】
什么是多源复制? 首先,我们需要清楚 multi-master 与multi-source 复制不是一样的. Multi-Master 复制通常是环形复制, 你可以在任意主机上将数据复制给其他主机. ...
最新文章
- 多个旅游网站被挂马 五一假期外出旅游应小心
- linux系统脚本安装失败,ubuntu16.04下vim安装失败的原因分析及解决方案
- 官方版.NET SDK连线更新(2011/01/19)
- 机器学习---人脸对齐的基于形状模型的训练
- 联想g510拆键盘的简单方法_宏基4552g拆键盘怎么操作
- java中求矩形面积,java求矩形面积
- 计算机程序设计艺术初读感
- 购物车结算页面案例jQuery
- 苹果或将采用高通屏下指纹方案,5GiPhone基带由三星、高通共同提供...
- 录屏软件OBS录屏时噪声大的解决办法
- 虚拟机怎么连云服务器,虚拟机怎么连接云服务器
- i2c信号的ACK与NACK
- C语言实现选择排序——堆排序(大根堆、小根堆)
- 计算机网络—IP头部结构,TCP头部结构,UDP头部结构
- 【RT-Thread】UART串口设备驱动★DLT645-2007多功能电能表通信协议★RTThread★
- 面试过阿里的P7大佬分享:180+道Java面试题目!含答案解析!
- easyx库的介绍与使用
- 电大计算机专业英语形成性考试,《计算机专业英语》形成性考核册答案
- 选择正确的CE版本然后下载
- 访问mysql的urn地址,URL,URI 和URN 之间的区别
热门文章
- c++层次遍历_动画:二叉树遍历的多种姿势
- python 从excel中抓取数据_使用Python抓取美团数据存于Excel中
- 显卡在电脑什么位置_DIY组装电脑教程,新手也能学会自己组装电脑
- linux如何设置浏览器,如何从 命令行 设置默认浏览器?
- cocos2d js调用java_【cocos2d-js官方文档】二十四、如何在android平台上使用js直接调用Java方法...
- jquery基本操作
- jpa关联映射(一)
- dos命令在vba中应用
- python学习之路day05——cmd操作命令
- 移动端适配 rem