mysql master 配置_MySQL双Master配置的方法详解
剛剛抽空做了一下MYSQL 的主主同步。把步驟寫下來,至于會出現的什么問題,以后隨時更新。這里我同步的數據庫是TEST1、環境描述。主機:192.168.0.231(A)主機:192.168.0.232(B)MYSQL 版本為5.1.212、授權用戶。A:mysql> grant replication slave,file on *.* to 'repl1'@'192.168.0.232' identifiedby '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)B:mysql> grant replication slave,file on *.* to 'repl2'@'192.168.0.231' identifiedby '123456';Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)然后都停止MYSQL 服務器。3、配置文件。在兩個機器上的my.cnf里面都開啟二進制日志 。A:user = mysqllog-bin=mysql-binserver-id?????? = 1binlog-do-db=testbinlog-ignore-db=mysqlreplicate-do-db=testreplicate-ignore-db=mysqllog-slave-updatesslave-skip-errors=all
skip-name-resolvesync_binlog=1auto_increment_increment=2auto_increment_offset=1B:user = mysqllog-bin=mysql-binserver-id?????? = 2binlog-do-db=testbinlog-ignore-db=mysqlreplicate-do-db=testreplicate-ignore-db=mysqllog-slave-updatesslave-skip-errors=all
skip-name-resolvesync_binlog=1auto_increment_increment=2auto_increment_offset=2至于這些參數的說明具體看手冊。紅色的部分非常重要,如果一個MASTER 掛掉的話,另外一個馬上接管。紫紅色的部分指的是服務器頻繁的刷新日志。這個保證了在其中一臺掛掉的話,日志刷新到另外一臺。從而保證了數據的同步 。4、重新啟動MYSQL服務器。在A和B上執行相同的步驟[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe &[1] 4264[root@localhost ~]# 071213 14:53:20 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'./usr/local/mysql/bin/mysqld_safe: line 366: [: -eq: unary operator expected071213 14:53:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data5、進入MYSQL的SHELL。A:mysql> flush tables with read lock\GQuery OK, 0 rows affected (0.00 sec)mysql> show master status\G*************************** 1. row ***************************File: mysql-bin.000007Position: 528Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)B:mysql> flush tables with read lock;Query OK, 0 rows affected (0.00 sec)mysql> show master status\G*************************** 1. row ***************************File: mysql-bin.000004Position: 595Binlog_Do_DB: testBinlog_Ignore_DB: mysql1 row in set (0.00 sec)然后備份自己的數據,保持兩個機器的數據一致。方法很多。完了后看下一步。6、在各自機器上執行CHANGE MASTER TO命令。A:mysql> change master to-> master_host='192.168.0.232',-> master_user='repl2',-> master_password='123456',-> master_log_file='mysql-bin.000004',-> master_log_pos=595;Query OK, 0 rows affected (0.01 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)B:mysql> change master to-> master_host='192.168.0.231',-> master_user='repl1',-> master_password='123456',-> master_log_file='mysql-bin.000007',-> master_log_pos=528;Query OK, 0 rows affected (0.01 sec)mysql> start slave;Query OK, 0 rows affected (0.00 sec)7、查看各自機器上的IO進程和 SLAVE進程是否都開啟。A:mysql> show processlist\G*************************** 1. row ***************************Id: 2User: replHost: 192.168.0.232:54475db: NULLCommand: Binlog DumpTime: 1590State: Has sent all binlog to slave; waiting for binlog to be updatedInfo: NULL*************************** 2. row ***************************Id: 3User: system userHost:db: NULLCommand: ConnectTime: 1350State: Waiting for master to send eventInfo: NULL*************************** 3. row ***************************Id: 4User: system userHost:db: NULLCommand: ConnectTime: 1149State: Has read all relay log; waiting for the slave I/O thread to update itInfo: NULL*************************** 4. row ***************************Id: 5User: rootHost: localhostdb: testCommand: QueryTime: 0State: NULLInfo: show processlist4 rows in set (0.00 sec)B:mysql> show processlist\G*************************** 1. row ***************************Id: 1User: system userHost:db: NULLCommand: ConnectTime: 2130State: Waiting for master to send eventInfo: NULL*************************** 2. row ***************************Id: 2User: system userHost:db: NULLCommand: ConnectTime: 1223State: Has read all relay log; waiting for the slave I/O thread to update itInfo: NULL*************************** 3. row ***************************Id: 4User: rootHost: localhostdb: testCommand: QueryTime: 0State: NULLInfo: show processlist*************************** 4. row ***************************Id: 5User: repl2Host: 192.168.0.231:50718db: NULLCommand: Binlog DumpTime: 1398State: Has sent all binlog to slave; waiting for binlog to be updatedInfo: NULL4 rows in set (0.00 sec)如果紅色部分沒有出現,檢查DATA目錄下的錯誤文件。8、釋放掉各自的鎖,然后進行插數據測試。mysql> unlock tables;Query OK, 0 rows affected (0.00 sec)插入之前兩個機器表的對比:A:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb???? || t22??????????? |+----------------+B:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb???? || t22??????????? |+----------------+從A機器上進行插入A:mysql> create table t11_replicas-> (id int not null auto_increment primary key,-> str varchar(255) not null) engine myisam;Query OK, 0 rows affected (0.01 sec)mysql> insert into t11_replicas(str) values-> ('This is a master to master test table');Query OK, 1 row affected (0.01 sec)mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb???? || t11_replicas?? || t22??????????? |+----------------+3 rows in set (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str?????????????????????????????????? |+----+---------------------------------------+|? 1 | This is a master to master test table |+----+---------------------------------------+1 row in set (0.00 sec)現在來看B機器:mysql> show tables;+----------------+| Tables_in_test |+----------------+| t11_innodb???? || t11_replicas?? || t22??????????? |+----------------+3 rows in set (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str?????????????????????????????????? |+----+---------------------------------------+|? 1 | This is a master to master test table |+----+---------------------------------------+1 row in set (0.00 sec)現在反過來從B機器上插入數據:B:mysql> insert into t11_replicas(str) values('This is a test 2');Query OK, 1 row affected (0.00 sec)mysql> select * from t11_replicas;+----+---------------------------------------+| id | str?????????????????????????????????? |+----+---------------------------------------+|? 1 | This is a master to master test table ||? 2 | This is a test 2????????????????????? |+----+---------------------------------------+2 rows in set (0.00 sec)我們來看AA:mysql> select * from t11_replicas;+----+---------------------------------------+| id | str?????????????????????????????????? |+----+---------------------------------------+|? 1 | This is a master to master test table ||? 2 | This is a test 2????????????????????? |+----+---------------------------------------+2 rows in set (0.00 sec)好了。現在兩個表互相為MASTER。
本文標題: MySQL雙Master配置的方法詳解
本文地址: http://www.cppcns.com/shujuku/mysql/96842.html
總結
以上是生活随笔為你收集整理的mysql master 配置_MySQL双Master配置的方法详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2017微服务 mysql集群_成功升P
- 下一篇: 过程声明与同名事件或过程的描述不匹配_多