MySQL主主复制-创新互联
MySQL主主复制其实就是基于主从复制做的双向同步。
成都创新互联是一家专业提供官渡企业网站建设,专注与成都做网站、网站制作、HTML5建站、小程序制作等业务。10年已为官渡众多企业、政府机构等服务。创新互联专业网站设计公司优惠进行中。主从复制:对master做操作会同步到slave,对slave做操作不会同步到master;
主主复制:可以向两台MySQL做操作,并且都可以同步到另外一台MySQL数据库。
一.配置主从复制
请参考主从复制博文(http://guoxh.blog.51cto.com/10976315/1922643)
二.配置主主复制
1.修改MySQL配置文件
master:开启中继日志
编辑/etc/my.conf添加 relay-log=relay-log-bin relay-log-index=slave-relay-bin.index 重启服务 [root@master~]# service mysqld restartslave:开启二进制日志
编辑/etc/my.conf添加 log-bin=master-bin log-slave-update=true 重启服务 [root@slave ~]# service mysqld restart2.配置同步
上一篇文章中已在master添加授权账号,并且在slave上面配置同步操作;
这里只需要配置slave添加授权账号,在master上面配置同步操作;
slave:
mysql> grant replication slave on *.* to 'slave'@'192.168.0.%' identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-bin.000001 | 106| | | +-------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)master:
mysql> change master to master_host='192.168.0.135',master_user='slave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=106; Query OK, 0 rows affected (0.40 sec) mysql> start slave; #启动同步 Query OK, 0 rows affected (0.00 sec) mysql> show slave status \G #查看同步状态 *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.135 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000005 Read_Master_Log_Pos: 106 Relay_Log_File: relay-log-bin.000012 Relay_Log_Pos: 252 Relay_Master_Log_File: master-bin.000005 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: 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: 106 Relay_Log_Space: 551 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: 1 row in set (0.00 sec)#Slave_IO和Slave_SQL为YES说明同步成功。
三.测试
1.在slave上面新建一个数据库
mysql> create database master; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | aaa | | master | | mysql | | test | +--------------------+ 5 rows in set (0.00 sec)2.在master上面查看
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | aaa | | master | | mysql | | test | +--------------------+ 5 rows in set (0.00 sec)3.在master删除一个数据库
mysql> drop database aaa; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | master | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec)4.在slave上面查看
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | master | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec)#到这里,MySQL主主复制配置完毕!
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章标题:MySQL主主复制-创新互联
标题URL:http://azwzsj.com/article/doepgh.html