mysq5.7 主主同步

db01  172.21.0.10

db02  172.21.0.14

一、安装数据库看上一遍博客

修改配置文件  db01  172.21.0.10

[root@VM_0_10_centos mysql]# cat /etc/my.cnf 
[mysqld]
port=3306
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#innodb_buffer_pool_size=8M
max_connections=1000
slow_query_log = 1
slow_query_log_file=/usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
max_connections=1000log-bin=/usr/local/mysql/log_bin/mysql-bin.log  # 开启二进制日志
binlog_format=mixed
server-id = 1
auto_increment_increment=2 # 步进值auto_imcrement。一般有n台主 MySQL 就填n
auto_increment_offset=1 # 起始值。一般填第n台主MySQL。此时为第一台主MySQL
replicate-do-db=schneider # 要同步的数据库,默认所有库
expire_logs_days=180  #binlog过期清理时间     
max_binlog_size=512m  #binlog每个日志文件大小
replicate-do-db=schneider # 要同步的数据库,默认所有库[mysqld_safe]log-error=/usr/local/mysql/data/error.logpid-file=/usr/local/mysql/data/mysql.pidtmpdir=/usr/local/mysql/tmp[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

 修改配置文件  db01  172.21.0.14

[root@VM_0_14_centos log_bin]# cat /etc/my.cnf 
[mysqld]
port=3306
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#innodb_buffer_pool_size=8M
max_connections=1000
slow_query_log = 1
slow_query_log_file=/usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5
max_connections=1000log-bin=/usr/local/mysql/log_bin/mysql-bin.log  # 开启二进制日志
binlog_format=mixed
server-id = 2 #id 不能一样
auto_increment_increment=2 # 步进值auto_imcrement。一般有n台主 MySQL 就填n
auto_increment_offset=2 # 起始值。一般填第n台主MySQL。此时为第一台主MySQL
replicate-do-db=schneider # 要同步的数据库,默认所有库
expire_logs_days=180  #binlog过期清理时间     
max_binlog_size=512m  #binlog每个日志文件大小
replicate-do-db=schneider # 要同步的数据库,默认所有库[mysqld_safe]log-error=/usr/local/mysql/data/error.logpid-file=/usr/local/mysql/data/mysql.pidtmpdir=/usr/local/mysql/tmp[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

 二、互换主从 注意需要锁表 或者停库

 db01  172.21.0.10

# 创建用户 并授权CREATE USER 'mysq114'@'172.21.0.14' IDENTIFIED BY '123456';GRANT REPLICATION SLAVE ON *.* TO 'mysq114'@'172.21.0.14' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;mysql>  show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

# 告诉bin-log位置  在db02  172.21.0.14 执行

CHANGE MASTER TO 
MASTER_HOST='172.21.0.10', 
MASTER_USER='mysq114', 
MASTER_PASSWORD='123456', 
MASTER_LOG_FILE='mysql-bin.000003', 
MASTER_LOG_POS= 154; 

db02  172.21.0.14 

 CREATE USER 'mysql10'@'172.21.0.10' IDENTIFIED BY '123456';GRANT REPLICATION SLAVE ON *.* TO 'mysql10'@'172.21.0.10' IDENTIFIED BY '123456';FLUSH PRIVILEGES;mysql>  show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |      154 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

 # 告诉bin-log位置  在db01  172.21.0.10 执行 

 CHANGE MASTER TO 
MASTER_HOST='172.21.0.14', 
MASTER_USER='mysql10', 
MASTER_PASSWORD='123456', 
MASTER_LOG_FILE='mysql-bin.000003', 
MASTER_LOG_POS= 154;

 三、查看结果 

db1 和db2 都执行start slave;

 db01  172.21.0.10

mysql>  show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 172.21.0.14Master_User: mysql10Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 474Relay_Log_File: VM_0_10_centos-relay-bin.000006Relay_Log_Pos: 687Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: schneiderReplicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 474Relay_Log_Space: 1069Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2Master_UUID: 9e57cecc-d148-11e9-92db-5254007bbb3cMaster_Info_File: /data/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 
1 row in set (0.00 sec)

 db02  172.21.0.14

mysql>  show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 172.21.0.10Master_User: mysq114Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000004Read_Master_Log_Pos: 355Relay_Log_File: VM_0_14_centos-relay-bin.000005Relay_Log_Pos: 568Relay_Master_Log_File: mysql-bin.000004Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: schneiderReplicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 355Relay_Log_Space: 950Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1Master_UUID: 9a3346c4-d148-11e9-a4f1-525400857720Master_Info_File: /data/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 
1 row in set (0.00 sec)

 四、最后测试是否同步 

 

转载于:https://www.cnblogs.com/zhaojingyu/p/11482065.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/409882.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

代码整洁之道 python_Python代码整洁之道:编写优雅的代码

译者序前言致谢关于作者关于技术审校者第1章 关于Python的思考11.1 编写Python代码11.1.1 命名21.1.2 代码中的表达式和语句51.1.3 拥抱Python编写代码的方式81.2 使用文档字符串141.2.1 模块级文档字符串171.2.2 使类文档字符串具有描述性171.2.3 函数文档字符串181.…

python猜数字游戏实例_Python案例:猜数字小游戏,由浅入深!

本案例只适合新手,老司机请绕路。 游戏介绍:程序自己有一个数字,用户输入一个数字,两个数字进行比较。 可以学到的知识点:input函数、字符串、while循环、if条件判断语句、break语句。 一、 简单版 猜数字游戏&#xf…

PLSQL

每个语句可加“;”也可以不加“;”但是连在一起执行必须加“;”delete taccorequest;commit;select * from taccorequest;转载于:https://www.cnblogs.com/JackShao/archive/2012/04/30/2476942.html

基于DispatchProxy打造自定义AOP组件

DispatchProxy是微软爸爸编写的一个代理类,基于这个,我扩展了一个AOP组件 暂时不支持依赖注入构造方法,感觉属性注入略显麻烦,暂时没打算支持 基于特性的注入流程 [AttributeUsage(AttributeTargets.Method)]internal class TestA…

算法整理学习(二)

(注:以下算法答案来自网络,自己整理供学习) 3.约瑟夫循环报数出列顺序问题思路:采用循环链表,当然也可以采用数组,像模拟循环队列一样 //方法一: 采用找到一个节点删除一个节点的方式…

python判断ip能否ping通_使用Python测试Ping主机IP和某端口是否开放的实例

使用Python方法比用各种命令方便,可以设置超时时间,到底通不通,端口是否开放一眼能看出来。命令和返回完整权限,可以ping通,端口开放,结果如下:无root权限(省略了ping),端口开放&…

python实现抓取网页上的内容并发送到邮箱

要达到的目的:从特定网页中抓取信息,排版后发送到邮箱中 关键点:下载网页,从网页里抓取出需要的信息HTML排版发送到指定邮箱 实现:1.python下载网页直接用库函数就可以实现from urllib import urlretrievefrom urllib …

Thinkphp 配置不用输入index.php

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/u011186019/article/details/78495461由:http://127.0.0.1/thinkphp/index.php/index/in…

ue4导入倾斜摄影_倾斜摄影建模干货|还怕搞不定CC空三?这里只要5分钟……

关注公众号"三维前沿",持续获取更多操作技巧干货!01Q:空三刚开始就失败?A:考虑以下4种情况:考虑ContextCapture Engine 是否打开,尝试关闭后重新打开;考虑相片数量是否过多…

[html] 如何禁止移动端的左右划动手势?

[html] 如何禁止移动端的左右划动手势? html{touch-action:none;touch-action:pan-y;}个人简介 我是歌谣,欢迎和大家一起交流前后端知识。放弃很容易, 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

python自增_python mysql自增字段AUTO_INCREMENT值的修改方式

在之前得文章中我们说过,如果使用delete对数据库中得表进行删除,那么只是把记录删除掉,并且id的值还会保持上次的状态。 即删除之前如果有四条数据,删除之后,再添加新的数据,id怎会从5开始。 但是我们显示想…

Python工具

1. sourcetree https://www.cnblogs.com/hoobey/p/7100593.html 2.pycharm 3. anaconda 转载于:https://www.cnblogs.com/ericazy/p/11498959.html

graphpad两组t检验_GraphPad prism -- t检验操作步骤解析~

ZSCIt检验&#xff0c;主要用于样本含量较小(例如 n<30)&#xff0c;总体标准差 σ 未知的正态分布资料&#xff0c;其中又将其分为了配对t检验和成组t检验&#xff0c;那如何利用GraphPad prism进行t检验呢&#xff1f;一、原理及意义配对t检验&#xff1a;又称配对样本均数…

[html] 在两个iframe之间传递参数的方法有哪些?

[html] 在两个iframe之间传递参数的方法有哪些&#xff1f; 通过postMessage与父级通过&#xff0c;父级传递消息通过websocket通信如果是同一个域名下可用stroage&#xff0c;监听storageChange事件通信通过web worker也可通信个人简介 我是歌谣&#xff0c;欢迎和大家一起交…

Java官方操纵byte数组的方式

java官方提供了一种操作字节数组的方法——内存流&#xff08;字节数组流&#xff09;ByteArrayInputStream、ByteArrayOutputStream ByteArrayOutputStream——byte数组合并 /*** 将所有的字节数组全部写入内存中&#xff0c;之后将其转化为字节数组*/public static void main…

python js返回 json_[python爬虫]把js转化成json

有一个优秀的库可以使用————demjson目标链接请求上面链接&#xff0c;会得到如下图的一个js文件我们需要把这个js文件转成为dict&#xff0c;方便提取其中需要的字段(这在爬虫任务中非常常见)失败的方法传统方法通常转js文件为dict的过程&#xff1a;1.先通过切片掐头去尾&…

springboot security 权限不足_springBoot整合springSecurity(零一)

整体结构》》》1&#xff0c;springboot2.0整合springSecurity5.1.12&#xff0c;mysql--->>InnoDB3&#xff0c;持久层我用的是用MybatiysPlus(这里就不写关于这个的了,基本是查)4&#xff0c;web服务不是jar服务5&#xff0c;数据库表》账户表/角色表/权限表/账户角色关…

聊聊PowerJob的OmsLogHandler

序 本文主要研究一下PowerJob的OmsLogHandler OmsLogHandler tech/powerjob/worker/background/OmsLogHandler.java Slf4j public class OmsLogHandler {private final String workerAddress;private final Transporter transporter;private final ServerDiscoveryService …

[html] 为什么移动端页面的设计稿一般是750px/640px呢?

[html] 为什么移动端页面的设计稿一般是750px/640px呢&#xff1f; 750px 代表iphone6或inphone6s 设备的像素(宽) 640px 代表inpone3Gs&#xff0c;inpone4/4s iphone5系列 设备的像素(宽) 其他手机大多数时这两种规格 750px/640px 代表的逻辑像素是 375px/320px&#xff0c;…

m文件中函数的执行顺序

当进行多个GUI协同工作时&#xff0c;要用到uiwait和uiresume函数。此时&#xff0c;理解函数的执行顺序此时是很关键的。 首先理解uiwait和uiresume函数的作用。 uiwait函数&#xff1a;阻塞m文件的执行&#xff0c;直到uiresume解除这种阻塞&#xff1b; uiresume函数&#x…