Get the App
SLTechnology News&Howtos  ›  Database  › 

How to configure double master in mysql

Shulou Source: shulou.com Published: 2022-05-31 17:58:49 10月22日 Update

This article is about how to configure double master in mysql. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Double master configuration of mysql

Suppose the ip of the two machines is 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 both servers:

Mysql: > create user 'repl'@'%' identified by' 135246password;-- create user repl password 135246

The server executes:

Mysql: > grant replication client,replication slave on *. * to 'repl'@'192.168.14.38' identified by' 135246 server;-- authorized server one can access server two remotely

Server 2 executes:

Mysql: > grant replication client,replication slave on *. * to 'repl'@'192.168.14.37' identified by' 135246 server;-- license server 2 can access server 1 remotely

Verify (enter the password when prompted):

Connect server two on server one

Mysql-h 192.168.14.38-u repl-p

Connect 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:

[client] default-character-set=utf8 [mysql] default-character-set= UTF8 [mysqld] server_id = 1log-bincharacter-set-server=utf8# table name is case-insensitive lower_case_table_names=1#server_id = slave uniquely identify is 2show master status

You can get the MASTER_LOG_FILE and MASTER_LOG_POS information of server one and server two.

Suppose the first server is "localhost-bin.000004" and the second is "localhost-bin.000005" and "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

Execute on server 2:

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 primary primary synchronization is successful:

Add table example to server-mysql

Mysql: > create database example1; use example1;create table example1 (length int)

Finally, check server 2 to see if there is this database, this table, and this piece of data.

View synchronization status: show slave status\ G

If something goes wrong, you can see the error log.

Error leads to synchronization failure refer to mysql slave-skip-errors=all for in-depth understanding

Note: the two servers will not synchronize the data before setting double master.

Thank you for reading! This is the end of the article on "how to configure double master in mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Server service synchronization configuration content data machine password more user article reference verification good practical successful two two information size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Shulou Information Shulou Technology Huawei