Previously wrote a mysql master slave master-Slave Synchronization (replication) configuration, the database backup level. Now the demand is that both servers are equipped with a database, in order to prevent a server problems and affect the operation of the business, need to prepare two servers to run MySQL, and need two server data is kept synchronized. That is to say now MySQL bidirectional synchronization, the implementation of database main standby mode.
Basic Environment
Operating Server System: Ubuntu 12.04 64-bit
Database version: MYSQL 5.1 +
Two servers ip:192.168.1.2 192.168.1.3
Sync Account Settings
The first is to add a new login account on both servers.
Grant all privileges in db_name.* to ' dbuser ' @ ' 192.168.1.3 ' identified by ' Dbpassword ';
Flush privileges;
Grant all privileges in db_name.* to ' dbuser ' @ ' 192.168.1.2 ' identified by ' Dbpassword ';
Flush privileges;
Data View Configuration
First modify the database configuration file for the first server:
Vi/etc/mysql/my.cnf
Add the following information to the configuration of [mysqld]:
Default-character-set=utf8
Log-bin=mysql-bin
Relay-log=relay-bin
Relay-log-index=relay-bin-index
Server-id=1 #服务器ID
master-host=192.168.1.2
Master-user=root
Master-password=pwd123
master-port=3306
Master-connect-retry=30
Binlog-do-db=abc
Replicate-do-db=db_name # The database to synchronize
Replicate-ignore-table=udb.table #不同步的表
Note: Notice in the above additions that if there are multiple databases and there is no need to sync, you need to add replicate-ignore-db, followed by a database name that is not synchronized.
Similarly, modify the configuration file on another database server:/ETC/MYSQL/MY.CNF
Default-character-set=utf8
Log-bin=mysql-bin
Relay-log=relay-bin
Relay-log-index=relay-bin-index
Server-id=1 #服务器ID
master-host=192.168.1.3
Master-user=root
Master-password=pwd123
master-port=3306
Master-connect-retry=30
Binlog-do-db=abc
Replicate-do-db=db_name # The database to synchronize
Replicate-ignore-table=udb.table #不同步的表
Manually perform synchronization
A primary server, restart the database for Server B:
Service MySQL Restart
Then execute:
Stop slave
Manual synchronization:
Load data from Master;
Then start synchronization:
Start slave;
Reboot a server MySQL;
To view the synchronization status of a database:
show slave status\g;
View:
Slave_io_running:yes
Slave_sql_running:yes
If the above two values are yes, then the success is indicated.
Problem
If there is a large synchronization delay, you need to modify the configuration file:
Slave-net-timeout = 30;
Reboot can be.