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主主同步的更多相关文章

  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. MYSQL主从同步/主主同步

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

  8. MySQL主主同步配置

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

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

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

  10. mysql主主同步设置

    mysql主主同步设置 主主同步设置是同等的地位,所以以下操作在两台机器上都需要进行而且操作是相同的. 服务器 服务器代号 IP hostname A 192.168.70.128 Debian1 B ...

随机推荐

  1. 51nod——1432 独木桥

    https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1432 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 ...

  2. 计算机与linux操作系统的发展

    一.计算机 (一)计算机的概念 1.概念:计算机(computer)俗称电脑,是一种用于高速计算的电子计算机器,可以进行数值计算,又可以进行逻辑计算,还具有存储记忆功能.是能够按照程序运行,自动.高速 ...

  3. AspNet MVC4 教学-27:Asp.Net MVC4 自己定义helper及function的高速Demo

    A.创建Basic类型项目. B.创建App_Code目录,在里面创建2个cshtml文件: MyHelper.cshtml: @helper MyTruncate(string input, int ...

  4. B1192 [HNOI2006]超级英雄Hero 二分图匹配

    先检讨一下,前一段时间开学,做题懒得发博客,也不总结...现在捡起来. 这个题一看是裸的二分图匹配,但是仔细一看还有一些区别,就是必须要连续的连接,否则直接退出.因为前一道题答不出来的话后面的题就没有 ...

  5. How to build CppCMS 1.x.x

    How to build CppCMS 1.x.x Requirements Mandatory Requirements Recommended Dependencies Suggested Dep ...

  6. 90.商城登录页面Extjs

    1. Ext.onReady(function(){ Ext.BLANK_IMAGE_URL = "Ext/resources/images/default/s.gif"; Ext ...

  7. El表达式日期处理

    第1步:引入指令  <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt " %&g ...

  8. APPStore 发布流程及证书申请

    最新的 iOS 申请证书与发布流程(2016.7) 今天刚好客户定制的APP需要上架,也提供了新的开发者账号,所以就顺带把申请证书与发布流程写一遍. 证书是什么? 上面这个就是我们申请好证书后,下载到 ...

  9. UIView动画基础

    1 Position 平移 [UIView animateWithDuration:1.0 animations:^{ _blueView.centerX = self.view.width -100 ...

  10. ROS-TF-监听

    前言:监听第一只海龟的位置,然后让第二只海龟跟随第一只海龟. 通过监听tf,我们可以避免繁琐的旋转矩阵的计算,而直接获取我们需要的相关信息. 一.新建cpp文件 新建turtle_tf_listene ...