Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the master replication schema in Mysql

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to configure the master replication architecture in Mysql. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The MySQL master replication structure is different from the master-slave replication structure. In the master master replication structure, any of the two servers

Any change in the data inventory above will be synchronized to another server, so that the two servers

They are master and subordinate to each other, and can provide services to the outside world. This has better performance than using master-slave replication.

Next I will use two identical servers to achieve this effect:

Server1_mysql:192.168.1.108

Server2_mysql: 192.168.1.110

Topology:

Server1_mysql-server2_mysql

1. Create users and authorize

Server1:

Mysql > GRANT REPLICATION SLAVE ON *. * TO

IDENTIFIED BY 'server2'

Server2:

Mysql > GRANT REPLICATION SLAVE ON *. * TO

IDENTIFIED BY 'server1'

two。 Modify the main configuration file of Mysql

Server1:

[mysqld]

Server-id = 10

Log-bin = mysql-bin

Replicate-do-db = mydb

Auto-increment-increment = 2 / / 2 per increase

Auto-increment-offset = 1 / / sets the offset of the automatically growing field, that is, the initial value is 2

Start the Mysql service:

# service mysqld restart

Server2:

[mysqld]

Server-id = 20

Log-bin = mysql-bin

Replicate-do-db = mydb

Auto-increment-increment = 2 / / 2 per increase

Auto-increment-offset = 2 / / sets the offset of the automatically growing field, that is, the initial value is 2

Start the Mysql service:

# service mysqld restart

Note: only server-id is different from auto-increment- offset.

The value of auto-increment-increment should be set to the total number of servers in the entire structure, and in this case two

Server, so the value is set to 2.

3. Restart both servers

# service mysqld restart

4. To make the two identical, we back up one of the databases and then restore them on the other

Again, so that the two databases are the same at the beginning.

Operate on server1:

# dump-- databases luowei > / tmp/luowei.sql

Operate on server2:

Create an empty database with the same name as mydb

# mysql

> CREATE DATABASE mydb

>\ Q

# scp 192.168.1.108:/tmp/mydb.sql. /

# mysql-uroot-p mydb

< /tmp/luowei.sql 5.然后两个服务器相互通告二进制日志的位置并启动复制功能: 在server1上: # mysql >

CHANGE MASTER TO

> MASTER_HOST='192.168.1.110'

> MASTER_USER='server2'

> MASTER_PASSWORD='server2'

Mysql > START SLAVE

On server2:

# mysql

> CHANGE MASTER TO

> MASTER_HOST='192.168.1.108'

> MASTER_USER='server1'

> MASTER_PASSWORD='server1'

Mysql > START SLAVE

6. View and verify:

View on two database servers

Mysql > START SLAVE

This is how to configure the master replication architecture in the Mysql shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report