一、修改配置文件my.cnf
服务器A(172.16.16.70)配置如下
server_id = 70
socket = /tmp/mysql.sock
innodb_buffer_pool_size = 10G
character-set-server=utf8
log_bin=mysql-bin
expire_logs_days=3
replicate-do-db=ixinnuo_sjcj
binlog-ignore-db=mysql,information_schema
auto-increment-increment = 2
auto-increment-offset = 1

服务器B(172.16.16.71)配置如下:
server_id = 71
socket = /tmp/mysql.sock
innodb_buffer_pool_size = 10G
character-set-server=utf8
log_bin=mysql-bin
expire_logs_days=3
replicate-do-db=ixinnuo_sjcj
replicate-ignore-db = mysql,information_schema
auto-increment-increment = 2
auto-increment-offset = 2

两台服务器都重启,使配置生效:
# service mysqld restart

说明:auto-increment-offset是用来设定数据库中自动增长的起点的,回为这两台服务器都设定了一次自动增长值2,所以它们的起点必须要不同,这样才能避免两台服务器数据同步时出现主键冲突.
replicate-do-db 指定同步的数据库,本例为ixinnuo_sjcj库,另外,建议两台服务器的硬件配置也都一样。

二、同步数据,建立复制账号:

在服务器A(172.16.16.70)上:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'172.16.16.71' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

在服务器B(172.16.16.71)上:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'172.16.16.70' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

三、执行change master命令同步:
在服务器A(172.16.16.70)上:
mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000047 |      411 |              | mysql,information_schema |                   |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

在服务器B(172.16.16.71)上:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 |      618 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

在服务器A上执行:
mysql> change master to master_host='172.16.16.71',master_user='slave',master_password='123456',master_log_file='mysql-bin.000003',master_log_pos=618;
Query OK, 0 rows affected, 2 warnings (0.29 sec)

在服务器B上执行:
mysql> change master to master_host='172.16.16.70',master_user='slave',master_password='123456',master_log_file='mysql-bin.000047',master_log_pos=411;
Query OK, 0 rows affected, 2 warnings (0.34 sec)

在两服务器都执行以下命令:
mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

四.查看状态:

A服务器(172.16.16.70)状态如下:
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.71
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 618
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: ixinnuo_sjcj
          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: 618
              Relay_Log_Space: 460
              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: 71
                  Master_UUID: 32197cd9-2957-11e7-a5c4-525400e493a4
             Master_Info_File: /usr/local/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           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
1 row in set (0.00 sec)

B服务器(172.16.16.71)状态如下:
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.16.70
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000047
          Read_Master_Log_Pos: 411
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000047
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: ixinnuo_sjcj
          Replicate_Ignore_DB: mysql,information_schema
           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: 411
              Relay_Log_Space: 460
              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: 70
                  Master_UUID: f1366940-266c-11e7-92c2-525400f39f79
             Master_Info_File: /usr/local/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           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
1 row in set (0.00 sec)

说明已经配置成功了

测试:
在服务器A(172.16.16.70)上ixinnuo_sjcj库里创建表chenfeng:

mysql> use ixinnuo_sjcj
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> create table chenfeng (name varchar(10));
Query OK, 0 rows affected (0.23 sec)

mysql> insert into chenfeng values('duansf');
Query OK, 1 row affected (0.13 sec)

mysql> insert into chenfeng values('liuyb');
Query OK, 1 row affected (0.02 sec)

在服务器B上查看服务器A上创建的表chenfeng
mysql> select * from chenfeng;
+--------+
| name   |
+--------+
| duansf |
| liuyb  |
+--------+
2 rows in set (0.00 sec)

mysql> desc chenfeng;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)

在服务器B(172.16.16.71)上ixinnuo_sjcj库里创建表duansf:

mysql> create table duansf (name varchar(20));
Query OK, 0 rows affected (0.18 sec)

mysql> insert into duansf values('duansf');
Query OK, 1 row affected (0.02 sec)

mysql> insert into duansf values('liuky');
Query OK, 1 row affected (0.03 sec)

在服务器上A上查看服务器B上创建的表duansf
mysql> select * from duansf;
+--------+
| name   |
+--------+
| duansf |
| liuky  |
+--------+
2 rows in set (0.00 sec)

mysql> desc duansf;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.00 sec)

测试成功,说明MySQL主主复制配置成功.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2137928/,如需转载,请注明出处,否则将追究法律责任。

MySQL主主复制(双主复制)配置过程介绍的更多相关文章

  1. MySQL Replication, 主从和双主配置

    MySQL Replication, 主从和双主配置 MySQL的Replication是一种多个MySQL的数据库做主从同步的方案,特点是异步,广泛用在各种对MySQL有更高性能,更高可靠性要求的场 ...

  2. nginx+keepalived 简单实现主备和双主模式

    准备nginx和keepalived 安装nginx(自行安装) yum install nginx 安装keepalived(安装包安装总报错,yum安装能好一点) yum install keep ...

  3. mysql传统主从、双主复制+keepalived配置步骤

    mysql主从.主主复制(双主复制)配置步骤 一:MySQL复制: MySQL复制简介: 将master服务器中主数据库的ddl和dml操作通过二进制日志传到slaves服务器上,然后在master服 ...

  4. linux系统mysql主主复制(双主复制)

    一.简介 在上一篇的主从复制中:http://www.cnblogs.com/lay2017/p/9043985.html 我们了解到,mysql通过master写日志,slave读取并执行日志内容从 ...

  5. mycat 1.6.6.1安装以及配置docker 安装mysql 5.7.24 双主多从读写分离主主切换

    mycat和mysql的高可用参考如下两个图 简介:应用程序仅需要连接HAproxy或者mycat,后端服务器的读写分离由mycat进行控制,后端服务器数据的同步由MySQL主从同步进行控制. 服务器 ...

  6. mysql数据库之主从复制+双主--MMM

    mysql复制:在主数据库中,前端用户每执行一个写操作/语句,都会在二进制日志中保存一个事件,把这个事件从mysql的服务器中3306端口发送给从服务器,从服务器把这个事件接受下来,接受下来先保存在本 ...

  7. MySQL自动化安装(双主多从读写分离)

    shell #!/bin/bash # Create by # version 1.0 # // # # check out lockfile whether or not exist IsInput ...

  8. haproxy+keepalived主备与双主模式配置

    Haproxy+Keepalived主备模式 主备节点设置 主备节点上各安装配置haproxy,配置内容且要相同 global log 127.0.0.1 local2 chroot /var/lib ...

  9. mysql集群(双主)

    0.安装 所谓双主基本可以理解为两台服务器互为主备,其核心思路与主备配置相同. 服务器A: 内网IP: 10.44.94.219 服务器B: 内网IP: 10.44.94.97 1.配置服务器A lo ...

随机推荐

  1. div 内容自动换行

    如图: 1.自动换行 <div style="widht:100%;height:100%;word-wrap: break-word">111111111111111 ...

  2. Java中字符串比较的问题

    package com.hxl; import java.util.Scanner; public class Test { public static void main(String[] args ...

  3. Echarts官网展示

    1.参考实例 http://echarts.baidu.com/examples/ 点击去的效果: 2.配置项手册 http://echarts.baidu.com/option.html#title ...

  4. 使用loadrunner录制脚本的思路和注意要点

    基本思路如下图: 注意要点有如下几点: 1.性能测试往往需要准备大批量的数据,大批量数据的生成方法有很多种,常见的有: (1)编写SQL语句来插入数据 (2)使用DataFactory等专业的数据生成 ...

  5. SpringBoot统一错误处理

    1.处理错误请求页面 import org.springframework.stereotype.Controller; import org.springframework.web.bind.ann ...

  6. scala-Unit-3-Scala基础语法2

    一.定义方法.函数.及方法转换为函数 1.方法的定义: def  方法名(参数1:数据类型,参数2:数据类型...):返回值类型 ={ } 2.定义函数: val h1 = (a:Int,b:Int) ...

  7. Linux学习笔记9

    管道 pipe 如 : ls |less -MN 含义把ls 结果输出到less ls=|=more ls 命令 ls -a 展示隐藏的文件 隐藏文件一般以.开始 ls -t 以时间戳排序  ls - ...

  8. JS获取IOS版本号

    var str= navigator.userAgent.toLowerCase(); var ver=str.match(/cpu iphone os (.*?) like mac os/); if ...

  9. React-Native-Storage使用介绍

    react-native-storage 这是一个本地持久存储的封装,可以同时支持react-native(AsyncStorage)和浏览器(localStorage).ES6语法,promise异 ...

  10. Sunday串匹配算法 C语言实现

    unsigned char * sunday( void * a_buf1, unsigned int len1, void * a_buf2, unsigned int len2 ){ unsign ...