How to set up dual-active hot standby for MySQL under Win2008

Environment description

1) Server

hostA: 192.168.1.6

HostB: 192.168.1.7


2) System environment: Windows Server 2008R2 Standard 64-bit


3) MySQL version: mysql-5.5.43-winx64

--------------------------------------------------------------------------------------------------------------------

The experiment starts:

Step 1. Create a backup user

#Create a user dedicated to backup on host A, and only allow B to log in.

mysql>grant replication slave,file on *.* to 'repl1'@'192.168.1.7' identified by '123456';

mysql>flush privileges; // refresh the database

#Test whether the account is created successfully (on the B server)

mysql.exe -h192.168.1.6 -urepl1 -p123456


#Similarly create a user on host B

mysql>grant replication slave,file on *.* to 'repl2'@'192.168.1.6' identified by '123456';
mysql>flush privileges;

#Test whether the account is created successfully (on the A server)

mysql.exe -h192.168.1.7 -urepl2 -p123456

Remark: If the following error occurs, please try to change the password on the remote server and try again
ERROR 1045 (28000): Access denied for user 'repl1'@'192.168.1.7' (using password: YES)
Password change command: mysql- >update user set password=password("12345") where user="repl1";


Step 2. Configuration file: (configured in my.ini on two machines)
Note: Before modifying the file, run the following command and then close the MySQL service: (to prevent the local login with root after the file is modified)
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'runa#2013' WITH GRANT OPTION;

#A host
user = mysql
log-bin=mysql-bin
server-id = 1 //Unique ID
binlog-do-db=runarcc //Specify local database replication
binlog-do-db=runarcc1 //Add multiple database replication Add
binlog-ignore-db=mysql //Specify which databases to ignore locally replicate
replicate-do-db=runarcc //Specify the database that host B needs to replicate
replicate-do-db=runarcc1
replicate-ignore-db= mysql //Specify that host B ignores the replicated database
log-slave-updates //After the relay log is executed, whether these changes need to be included in its own binarylog. When host B needs to be the master of another server, it needs to be opened, that is, double log Masters backup each other.
slave-skip-errors=all
skip-name-resolve
sync_binlog=1
#Because each database server may insert data into the same table, if the table has an auto-growing primary key, then there will be a primary key conflict on multiple servers. The solution to this problem is to make the auto-increment primary key of each database discontinuous. In my case, 2 servers are required for backup, so auto_increment_increment is set to 2. And auto_increment_offset=1 indicates the serial number of this server. Starting from 1, it does not exceed 2.
auto_increment_increment=2    
auto_increment_offset=1



#B host
user = mysql
log-bin=mysql-bin
server-id = 2
binlog-do-db=runarcc
binlog-do-db=runarcc1
binlog-ignore-db=mysql
replicate-do -db=runarcc
replicate-do-db=runarcc1
replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
skip-name-resolve
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=2


Step 3. After the above configuration is completed, restart MySQL

#Execute the CHANGE MASTER TO command on each machine
# A change master to:
mysql>change master to
master_host='192.168.1.7',
master_user='repl2',
master_password='123456',
master_log_file='mysql-bin.000005' ,
master_log_pos=107;
Note: The last 2 values ​​should be viewed on the other machine through show master status;



mysql> start slave;                   //开始slave进程




# B change master to:
mysql> change master to
master_host='192.168.1.6',
master_user='repl1',
master_password='123456',
master_log_file='mysql-bin.000006',
master_log_pos=107;

mysql> start slave;


Step 4. After the above settings are completed, check the slave status. The two red marked parts show YES status, which means normal.

mysql>show slave status\G



Step 6. Test whether the databases of A and B are synchronized.



-------------------------------------------------- -------------------------------------------------- --------------------
The following are other blogs for reference

http://www.cnblogs.com/kristain/articles/4142970.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325614913&siteId=291194637