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=1000 log-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.log pid-file=/usr/local/mysql/data/mysql.pid tmpdir=/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=1000 log-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.log pid-file=/usr/local/mysql/data/mysql.pid tmpdir=/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 event
Master_Host: 172.21.0.14
Master_User: mysql10
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 474
Relay_Log_File: VM_0_10_centos-relay-bin.000006
Relay_Log_Pos: 687
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: schneider
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: 474
Relay_Log_Space: 1069
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: 2
Master_UUID: 9e57cecc-d148-11e9-92db-5254007bbb3c
Master_Info_File: /data/mysql/data/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_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 event
Master_Host: 172.21.0.10
Master_User: mysq114
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 355
Relay_Log_File: VM_0_14_centos-relay-bin.000005
Relay_Log_Pos: 568
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: schneider
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: 355
Relay_Log_Space: 950
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: 1
Master_UUID: 9a3346c4-d148-11e9-a4f1-525400857720
Master_Info_File: /data/mysql/data/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_TLS_Version:
1 row in set (0.00 sec)

 四、最后测试是否同步 

mysq5.7 主主同步的更多相关文章

  1. 4.MySQL 主主(m-m) 同步生产库标准同步操作实施流程

    通过MySQL参数配置使用主主前提: 1.表的主键自增. ################################################################# #m1-m ...

  2. MySQL数据的主从复制、半同步复制和主主复制详解

    一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...

  3. LVS+MYCAT+读写分离+MYSQL主备同步部署手册

    LVS+MYCAT+读写分离+MYSQL主备同步部署手册 1          配置MYSQL主备同步…. 2 1.1       测试环境… 2 1.2       配置主数据库… 2 1.2.1  ...

  4. MySQL数据的主从复制、半同步复制和主主复制详解-转

    一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...

  5. MySQL 主主同步配置和主从配置步骤

    ★预备知识 : 1.双机热备 对于双机热备这一概念,我搜索了很多资料,最后,还是按照大多数资料所讲分成广义与狭义两种意义来说. 从广义上讲,就是对于重要的服务,使用两台服务器,互相备份,共同执行同一服 ...

  6. 【转载】LVS+MYCAT+读写分离+MYSQL主备同步部署手册(邢锋)

    LVS+MYCAT+读写分离+MYSQL主备同步部署手册 1          配置MYSQL主备同步…. 2 1.1       测试环境… 2 1.2       配置主数据库… 2 1.2.1  ...

  7. github上forck一个分支之后,如何和主分支同步

    github forck一个分之后,如果过一段时间就会和主分支的差异比较大. 这样提交pr的时候 就会冲突,这个时候我们就需要和主分支同步代码 git remote add upstream git@ ...

  8. MYSQL主从同步/主主同步

    一.MYSQL主从同步 注意:进行主从同步操作时需要确保DB无写操作 flush tables with read lock:   //全局读锁定,执行了命令之后所有库所有表都被锁定只读. 1.在主机 ...

  9. MySQL主主同步配置

    1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...

  10. Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录

    Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...

随机推荐

  1. Python - 100天从新手到大师

    简单的说,Python是一个“优雅”.“明确”.“简单”的编程语言. 学习曲线低,非专业人士也能上手 开源系统,拥有强大的生态圈 解释型语言,完美的平台可移植性 支持面向对象和函数式编程 能够通过调用 ...

  2. Angular、React、Vue是什么?

    基于js语言的UI(组件)管理库 +数据+交互+组织 相当于iOS的uikit(UIView)

  3. HUSTOJ 有序表的最小和

    一次奇怪的AC经历...上周被这道题卡了3天... 传送门:http://oj.gdsyzx.edu.cn/problem.php?id=1475 题目描述 给出两个长度为n的有序表A和B,在A和B中 ...

  4. podium micro-frontends 简单试用

    以下是一个简单的podium 试用,包含了layout 以及podlets,使用docker 运行 podium 主要包含了两大部分 podlets 片段服务 layouts 片段组合服务 环境准备 ...

  5. OOO的CSS

    应ooo要求 寻找他手写一千年的css的继承人 html { background:#f7f7f7 url(images/bg-pattern.jpg) } body { margin:; paddi ...

  6. jupyter的补充

    目录 jupyter 的使用 常用命令模式快捷键: 常用编辑模式快捷键: jupyter 的使用 Cells状态分为命令模式和编辑模式,Enter进入编辑模式,ESC进入命令模式,命令模式和编辑模式下 ...

  7. k8s实现灰度发布

    灰度发布在实际生产部署中是经常被使用的方式,常规的方法是手动从前端LB(负载均衡)上将后端服务器摘掉,然后,停服务,最后上传代码,完成软连接更新.在使用CI/CD工具时,这个过程变得自动化了,我们只需 ...

  8. nginx.conf 配置解析之 server配置

    server{} 包含在http{}内部,每一个server{}都是一个虚拟主机(站点) 以下为nginx.conf配置文件中server{  }部分的内容. server { listen ; // ...

  9. shell 字符串转数组

    #!/bin/bash string="hello,shell,split,test" #将,替换为空格 array=(${string//,/ }) for var in ${a ...

  10. MySQL避免插入重复记录:唯一性约束

      mysql在存在主键冲突或者唯一键冲突的情况下,根据插入策略不同,一般有以下三种避免方法.1.insert ignore2.replace into3.insert on duplicate ke ...