Mysql master/master synchronization bitsCN.com
Server:
Host 192.168.1.101
Port 3306
Server B:
Host 192.168.1.102
Port 3306
1. authorized users:
Server
Mysql> grant replication slave, file on *. * to 'repl9' @ '192. 168.1.102 'identified by '20140901 ';
Query OK, 0 rows affected (0.01 sec)
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
Server B
Mysql> grant replication slave, file on *. * to 'repl8' @ '192. 168.1.101 'identified by '123 ';
Query OK, 0 rows affected (0.01 sec)
Mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
2. configuration file
Server
Log-bin = mysql-bin
Server-id = 1
Binlog-do-db = test
Binlog-ignore-db = mysql
Replicate-do-db = test
Replicate-ignore-db = mysql
Log-slave-updates
Slave-skip-errors = all
Sync_binlog = 1
Auto_increment_increment = 2
Auto_increment_offset = 1
Master-host = 192.168.1.102
Master-user = repl8
Masters-password = 1234568
Master-port = 3306
Server B
Log-bin = mysql-bin
Server-id = 2
Binlog-do-db = test
Binlog-ignore-db = mysql
Replicate-do-db = test
Replicate-ignore-db = mysql
Log-slave-updates
Slave-skip-errors = all
Sync_binlog = 1
Auto_increment_increment = 2
Auto_increment_offset = 2
Master-host = 192.168.1.101
Master-user = repl9
Masters-password = 1234569
Master-port = 3306
Start the server.
--------------------------------------------------
Q: the following error occurs when I log on to MySQL on another machine:
ERROR 2003 (HY000): Can't connect to MySQL server on 'X. x. x. X' (111)
A: The reason is that, considering the security factors of MySQL, the default configuration only allows local login.
Open the/etc/mysql/my. cnf file and find bind-address = 127.0.0.1 and change it to bind-address = 0.0.0.0.
Restart mysql: sudo/etc/init. d/mysql restart
==========================================================
101 increase, 102 do not synchronize ?????????
Mysql-h192.168.1.102-urepl8-p1234568 OK
102 increase, 101 synchronization
Mysql-h192.168.1.101-urepl9-p1234569 OK
Compare the two groups of show slave status/G;
102
Slave_IO_Running: No
Slave_ SQL _Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql
Sudo/etc/init. d/mysql restart
After sudo service mysql restart, it becomes: lave_IO_Running: YES
Problem (multiple primary auto-growth IDs are repeated)
Solution:
We only need to ensure that the auto-growth data inserted on the two servers is different.
For example, if A queries an odd ID and B inserts an even ID, you can define an algorithm if there are many servers.
Here we add parameters on A and B to implement parity insertion.
A: add parameters to my. ini.
Auto_increment_offset = 1
Auto_increment_increment = 2
In this case, the auto_increment field of A produces the following values: 1, 3, 5, 7 ,... And so on.
B: add parameters to my. ini.
Auto_increment_offset = 2
Auto_increment_increment = 2
In this way, the value produced by the auto_increment field of B is: 2, 4, 6, 8 ,... An even number of IDs.
As you can see, your auto_increment field will never be repeated among different servers, so there is no problem with the Master-Master structure. Of course, you can also use 3, 4, or N servers. you only need to ensure auto_increment_increment = N and then set auto_increment_offset to the appropriate initial value, our MySQL can have dozens of master servers at the same time, without repeated self-growth IDs.
Here we are talking about two MYSQL servers. you can also expand to multiple servers. the implementation method is similar.
A-> B-> C-> D->
Such a circular backup structure is formed. remember to design the self-growth ID (primary key). otherwise, errors may occur.
Author "whxhz"
BitsCN.com