MySQL Database dual principal (bidirectional) synchronous implementation of database double main hot standby

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.