MySQL bidirectional synchronization practices

Source: Internet
Author: User
MySQL bidirectional synchronization practices

MySQL Master/Slave server (replication) settings: 1. First, create an account for the slave server on the master server. 2. Step 1

If the applied user name and password can be used to access the master database, the user is successfully created. (Dual-machine Hot Standby is created on two machines respectively

Replication account ).
Assume that the IP addresses of the two machines are as follows:
Servera: 192.168.1.103 (SA)
Serverb: 192.168.1.108 (SB)
Back up a database and restore it to another machine. perform the following operations:

1. Create an account for replication on the two machines. The command is as follows:
Mysql> grant replication slave on *. * To 'username '@ 'host' identified by 'Password ';
Then perform tests on SA and Sb respectively.
Mysql-hserverip-ureplicationname-preplicationpassword
If the operation succeeds, the account is valid. Otherwise, you must add a new user. (Firewall settings)

Example
(SA)
Mysql> grant replication slave on *. * To 'backup '@ '192. 168.1.108 'identified by '123'

(SB)
Mysql> grant replication slave on *. * To 'backup '@ '192. 168.1.103 'identified by '123'

(SB)
Mysql-h192.168.1.103-ubackup-p123456

Stop the MySQL service of the two machines. Perform the following operations:

2. Edit the my. ini file of SA and add the following information under mysqld:

Server-id = 1 (master server ID, which cannot be repeated)
BINLOG-do-DB = dbfood (database to be copied)
Log-bin = "C:/mysqlbak/log" (where the log file is stored, the final parameter indicates the log file name, and replication is based on log)

Edit the my. ini file of Sb,
Server-id = 2 (master server ID, which cannot be repeated)

Restart the MySQL service of SA and sb

(SA)
Mysql> show Master Status \ G
Position: 107
File: dbfood-bin.000001

(SB)
Run:
Mysql> change master to master_host = '192. 168.0.103 ', master_user = 'backup', master_password = '2016 ',

Master_log_file = 'dbfood-bin.000001 ', master_log_pos = 0;

(SB)
Restart MySQL Service

Mysql> Start slave;

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.