Assume that the IP addresses of the two machines are machine one: 192.168.14.37 machine two: 192.168.14.38, and the server is linux Rhel 5.9
Execute the create user statement on two servers:
mysql:>create user 'repl'@'%' identified by '135246'; -- 创建用户 repl 密码 135246
Server one execution:
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.38' identified by '135246'; -- 授权服务器一可以远程访问服务器二
Server two execution:
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.37' identified by '135246'; -- 授权服务器二可以远程访问服务器一
Verification (enter the password according to the prompt) :
Connect to server two on server one
mysql -h 192.168.14.38 -u repl -p
Connect to server one on server two
mysql -h 192.168.14.37 -u repl -p
View mysql:
First:vi /etc/my.cnf
On server 1, add the following content:
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] server_id = 1 log-bin character-set-server=utf8 #表名不区分大小写 lower_case_table_names=1 #server_id = 1 # uniquely identify 从为2 show master status
You can get the MASTER_LOG_FILE and MASTER_LOG_POS information of server one and server two.
假设服务器一为 " localhost-bin.000004" 和 "120" 服务器二为 " localhost-bin.000005" 和 "667"
Execute on server one:
stop slave; CHANGE MASTER TO MASTER_HOST = '192.168.14.38', MASTER_USER = 'repl', MASTER_PASSWORD = '135246', MASTER_LOG_FILE = 'localhost-bin.000004', MASTER_LOG_POS = 120; start slave;
On the server Execute on the second server:
stop slave; CHANGE MASTER TO MASTER_HOST = '192.168.14.37', MASTER_USER = 'repl', MASTER_PASSWORD = '135246', MASTER_LOG_FILE = 'localhost-bin.000005', MASTER_LOG_POS = 667; start slave;
Finally verify whether the main-master synchronization is successful:
Add the table example
mysql:> create database example1 ; use example1; create table example1 (length int);
on server one mysql and finally check whether there is this database on server two. This table, and this data.
View the synchronization status:show slave status \G
If an error occurs, you can see the error log.
Errors causing synchronization failure refer to mysql slave-skip-errors=all for in-depth understanding
Note: The two servers will not be synchronized before setting the double master;
Recommended Study: "mysql video tutorial"