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 ...
随机推荐
- git游戏杂谈
git作为一个知名小游戏,在被Linus开发出来后就广受好评,在程序员圈子内迅速传播,以至于现在很多程序员可以一日无饭,却不能一日无git.是什么能让各路程序员如此着迷?今天,让我们走进git,看一看 ...
- [vagrant]第一次安装添加box出现问题汇总
1.本地文件要加全文件名和协议file:/// 2.The box failed to unpackage properly. Please verify that the box file you' ...
- 网络银行木马DYRE知多少(1)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXF1c2hp/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- Java 构造时成员初始化的陷阱
1.首先列出代码 Base.java public class Base { Base() { preProcess(); } void preProcess() {} } Derived.java ...
- 使用html5 FileReader获取图片,并异步上传到server(不使用iframe)
使用html5 FileReader获取图片,并异步上传到server(不使用iframe) 原理: 1.使用FileReader 读取图片的base64编码 2.使用ajax.把图片的base64编 ...
- 假脱机服务(SPOOLing service)
1. 基本含义 SPOOLing 是 Simultaneous Peripheral(外设) Operation On-Line(联机) 的缩写,是关于慢速字符设备(慢速外设,比如打印机)如何与计算机 ...
- Coursera Algorithms week1 算法分析 练习测验: Egg drop 扔鸡蛋问题
题目原文: Suppose that you have an n-story building (with floors 1 through n) and plenty of eggs. An egg ...
- 关于类和对象的进一步讨论之析构函数 C++
析构函数也是一个特殊的成员函数.它的作用与构造函数相反.它的名字是在类名的前面加一个“~”符号.在C++中“~”是位取反运算符.当对象的生命结束时,会自动执行解析函数.以下几种情况会执行析构函数: 1 ...
- P1966 火柴排队(逆序对)
P1966 火柴排队 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相同, 两列火柴之间的距离定义为: ∑(ai-bi) ...
- 正确的缩写document。querySelector
北京的夕阳,伴随淡淡的霾殇.从写字楼望去,光线是那么昏黄.没有孤雁,也没有霞光,遥想当年,还是 jQuery 独霸一方.那时的我们,写程序都习惯了使用 $,至少在对美元符号的喜爱上,与 PHP 达成了 ...