On the Red Hat Enterprise Linux platform, the MySQL master-slave synchronization principle is used to achieve two-way MySQL synchronization.
MySQL version: 5.5.28
Operating System: RHEL 5.8 32bit
Server1: 192.168.1.1
Configuration: my. cnf
- Server-id = 1
- Binlog-do-db = testdb
- Binlog-ignore-db = mysql
- Log-slave-updates
- Replicate-do-db = testdb
- Replicate-ignore-db = mysql
Synchronize the testdb database. The mysql database is not synchronized here.
New synchronization users:
- Grant replication slave on *. * to slaveuser@192.168.1.2 identified by '2013 ';
Start Sever1;
- Service mysql start
View the binlog file name and pos value of MySQL synchronization:
- Show master status;
Server2: 192.168.1.2
Configuration: my. cnf
- Server-id = 2
- Binlog-do-db = testdb
- Binlog-ignore-db = mysql
- Log-slave-updates
- Replicate-do-db = testdb
- Replicate-ignore-db = mysql
The configuration is basically the same as that of Sever1, but the server-id is different and cannot be the same. Remember to enable the binary log record in the [mysqld] configuration area: log-bin = mysql-bin
New synchronization users:
- Grant replication slave on *. * to slaveuser@192.168.1.1 identified by '2013 ';
Start Server2:
- Service mysql start
Configuration synchronization:
- Mysql> change master to master_host = '192. 168.1.1 ',
- Mysql> master_user = 'slaveuser ',
- Mysql> master_password = '123 ',
- Mysql> master_log_file = 'mysql-bin.20.20 ',
- Mysql> master_log_pos = 107;
- Mysql> slave start;
- Mysql> show slave status \ G;