Practical Environment Introduction:
Server Name |
IP |
System |
MySQL |
Odd.example.com |
192.168.1.116 |
Rhel-5.8 |
5.5.16 |
Even.example.com |
192.168.1.115 |
Rhel-5.8 |
5.5.16 |
Assume that the database to be synchronized is db_rocky.
(I) Create a synchronization user
On ODD
Mysql> grant replication slave on *. * to 'water' @ '192. 168.1.115 'identified by 'cdio2010 ';
Query OK, 0 rows affected (0.00 sec)
Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
On EVEN
Mysql> grant replication slave on *. * to 'water' @ '192. 168.1.116 'identified by 'cdio2010 ';
Query OK, 0 rows affected (0.11 sec)
Mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(Ii) modify the/etc/my. cnf configuration file and add the following content to it:
On ODD
[Mysqld]
Binlog-do-db = db_rocky # database for which logs need to be logged. If multiple databases are separated by commas (,), or multiple binlog-do-db options are used.
Binlog-ignore-db = mysql # databases that do not need to record hexadecimal logs. If multiple databases are separated by commas (,), or use the binlog-do-db option.
Replicate-do-db = db_rocky # the database to be synchronized. If multiple databases are separated by commas, or multiple replicate-do-db options are used.
Replicate-ignore-db = mysql, information_schema # databases that do not need to be synchronized. If multiple databases are separated by commas, or use multiple replicate-ignore-db options
# Synchronization parameters:
# Ensure that slave will receive write information from another master when it is mounted to any master.
Log-slave-updates
Sync_binlog = 1
Auto_increment_offset = 1
Auto_increment_increment = 2
Slave-skip-errors = all # filter out some errors without any major problems
On EVEN
[Mysqld]
Server-id = 2 # set a different id. Note that the default value in my. cnf is 1. Change the default value instead of adding a server-id.
Binlog-do-db = db_rocky # database for which binary logs need to be recorded. If multiple databases are separated by commas, or multiple binlog-do-db options are used
Binlog-ignore-db = mysql # database that does not need to record the hexadecimal log. If multiple databases are separated by commas, or multiple binlog-ignore-db options are used
# Databases to be synchronized
Replicate-do-db = db_rocky # the database to be synchronized. If multiple databases are separated by commas (,), or use the binlog-do-db option.
Replicate-ignore-db = mysql, information_schema # databases that do not need to be synchronized. If multiple databases are separated by commas, or use multiple binlog-do-db options
# Synchronization parameters:
# Ensure that slave will receive write information from another master when it is mounted to any master.
Log-slave-updates
Sync_binlog = 1
Auto_increment_offset = 2
Auto_increment_increment = 2
Slave-skip-errors = all # filter out some errors without any major problems