mysql主主同步
Mysql 主主同步方案
第一台机器主
[root@master ~]# vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=mysql-binlog
log-slave-updates=true
max_binlog_size=1024M
auto_increment_offset = 1
auto_increment_increment = 2
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = mysql
max_connections = 3000
max_connect_errors = 30
skip-character-set-client-handshake
init-connect='SET NAMES utf8'
character-set-server=utf8
wait_timeout=1800
interactive_timeout=1800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
[root@master ~]# systemctl restart mariadb
[root@master ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave on *.* to 'repl'@'192.168.30.24'identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000004 | 483 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
第2台
[root@master1 ~]# vim /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-binlog
log-slave-updates=true
max_binlog_size=1024M
auto_increment_offset = 2
auto_increment_increment = 2
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = mysql
max_connections = 3000
max_connect_errors = 30
skip-character-set-client-handshake
init-connect='SET NAMES utf8'
character-set-server=utf8
wait_timeout=1800
interactive_timeout=1800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index
[root@master1 ~]# systemctl restart mariadb
[root@master1 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave on *.* to 'repl'@'192.168.30.25'identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000001 | 483 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
测试环境,可以保证没数据写入,否则需要的步骤是:先masterA锁表-->masterA备份数据-->masterA数据表--> masterB 导入数据--> masterB设置主从-->查看主从
第1台机器
[root@master ~]# mysql -u root
MariaDB [(none)]> stop slave;
MariaDB [(none)]> change master to master_host='192.168.30.24',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-binlog.000001',master_log_pos=483;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G;
第2台机器
[root@master1 ~]# mysql -u root
MariaDB [(none)]> stop slave;
MariaDB [(none)]> change master to
-> master_host='192.168.30.25',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-binlog.000004',master_log_pos=483;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G;
第一台机器
MariaDB [(none)]> create database test01;
第二台机器查看是否同步
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sampdb |
| test |
| test01 |
+--------------------+
第二台机器
MariaDB [(none)]> create database test02;
查看第一台机器
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sampdb |
| test |
| test01 |
| test02 |
+--------------------+
7 rows in set (0.00 sec)
mysql主主同步的更多相关文章
- 4.MySQL 主主(m-m) 同步生产库标准同步操作实施流程
通过MySQL参数配置使用主主前提: 1.表的主键自增. ################################################################# #m1-m ...
- MySQL数据的主从复制、半同步复制和主主复制详解
一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...
- LVS+MYCAT+读写分离+MYSQL主备同步部署手册
LVS+MYCAT+读写分离+MYSQL主备同步部署手册 1 配置MYSQL主备同步…. 2 1.1 测试环境… 2 1.2 配置主数据库… 2 1.2.1 ...
- MySQL数据的主从复制、半同步复制和主主复制详解-转
一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...
- MySQL 主主同步配置和主从配置步骤
★预备知识 : 1.双机热备 对于双机热备这一概念,我搜索了很多资料,最后,还是按照大多数资料所讲分成广义与狭义两种意义来说. 从广义上讲,就是对于重要的服务,使用两台服务器,互相备份,共同执行同一服 ...
- 【转载】LVS+MYCAT+读写分离+MYSQL主备同步部署手册(邢锋)
LVS+MYCAT+读写分离+MYSQL主备同步部署手册 1 配置MYSQL主备同步…. 2 1.1 测试环境… 2 1.2 配置主数据库… 2 1.2.1 ...
- MYSQL主从同步/主主同步
一.MYSQL主从同步 注意:进行主从同步操作时需要确保DB无写操作 flush tables with read lock: //全局读锁定,执行了命令之后所有库所有表都被锁定只读. 1.在主机 ...
- MySQL主主同步配置
1. MySQL主主配置过程 在上一篇实现了主从同步的基础上,进行主主同步的配置. 这里用node19(主),node20(从)做修改,使得node19和node20变为主主同步配置模式 修改配置文件 ...
- Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录
Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...
- mysql主主同步设置
mysql主主同步设置 主主同步设置是同等的地位,所以以下操作在两台机器上都需要进行而且操作是相同的. 服务器 服务器代号 IP hostname A 192.168.70.128 Debian1 B ...
随机推荐
- D - Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- F2BPM 开发Api与RESTfull应用服务Api 层次关系及示例
目前越来越多的企业架构解决方案更加趋向于基于http协议“微服务”访问跨系统调用,而不使用统传的WebService调用,即通过RESTfull方式进行交互,更加轻量整合调用更加方便.本文档中所有F2 ...
- dataguard switchover to physical stnadby
首先做一系列的check check 当前primary 的 standby redo log是否存在 SQL> select * from v$logfile; GROUP# STATUS T ...
- IO 字节流学习
复制图片和MP3 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.Fil ...
- 寒城攻略:Listo 教你用 Swift 写IOS UI 项目计算器
之前总结过 Swift 的语言攻略,这里就不做赘述了,如今做一个实例计算器项目来介绍一下 Swift 的应用.(凝视已经全然.直接上代码) 先看一下效果图: 以下是详细的代码和解释: 分享快乐.开源中 ...
- http get请求获取server返回的应答数据
libcurl库中的參数CURLOPT_WRITEFUNCTION所设置的回调函数应该是这种: size_t fun_cb( char *ptr, size_t size, size_t nmemb, ...
- HDU1573 X问题【一元线性同余方程组】
题目链接: http://acm.hdu.edu.cn/showproblem.php? pid=1573 题目大意: 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X ...
- 飞信php接口 web service
<?php /** ┃ ┃ code is far away from bug with the animal protecting ┃ ┃ 神兽保佑, ...
- Linux批量生成生成帐户脚本,随机密码
此脚本应用于生产环境下生成帐户,也可生成成百上千个密码相同的帐户.脚本代码如下: 批量生成: #!/bin/bash for name in tom jerry joe jane do useradd ...
- E20170809-mk
collapse n. 垮台; (身体的) 衰弱; vt. 使倒塌; 使坍塌; 使瓦解; vi. 崩溃; 倒塌; 折叠; (尤指工作劳累后 ...