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 build mysql5.7.15 Master-Slave replication Environment

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

Share

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

This article shows you how to build a mysql5.7.15 master-slave replication environment, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Hardware Information:

Primary node:

Operating system: centos7

Ip: 192.168.10.11

Mysql version: 5.7.15

From Node 1:

Operating system: centos7

Ip: 192.168.10.12

Mysql version: 5.7.15

Slave Node 2:

Operating system: win-server-2008-r2

Ip: 192.168.10.13

Mysql version: 5.7.15

1. Master node configuration

1) modify the / etc/my.cnf file to add the following

Log_bin # Open binary log file

Server_id=1 # master server id number (value cannot be 0, I just started with 0, slave library cannot connect to master library)

2) Export the database to be the master and slave

Mysqldump-uroot-p-D dbname > xxxx.dmp

3) users commonly used to connect from libraries

Mysql > grant all privileges on dbname.* to replication@'192.168.10.%' identified by 'replication'

4) View the information of log_bin.

Mysql > show master status\ G

* * 1. Row *

File: node1-bin.000001

Position: 154

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set:

2. Configure from library node 1 (centos 7)

1) modify the / etc/my.cnf file by adding the following

Server_id=2

2) Import the data backed up by the master node into the library

Mysql-uroot-p-D dbname

< xxxx.dmp 3)设置master信息 mysql>

Chang master to

MASTER_HOST='192.168.10.11'

MASTER_USER='replication'

MASTER_PASSWORD='replication'

MASTER_PORT=3306

MASTER_LOG_FILE='node1-bin.000001'

MASTER_LOG_POS=154

MASTER_CONNECT_RETRY=10

4) start slave

Mysql > start slave

5) see the information of slave

Mysql > show slave status\ G

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.10.11

Master_User: replication

Master_Port: 3306

Connect_Retry: 60

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

The message did not report an error, indicating that the configuration was successful.

3. Configure from library node 2 (win-server8-r2)

1) modify the C:\ ProgramData\ MySQL\ MySQL Server 5.7\ my.cnf file by adding the following

Server_id=3

2) Import the data backed up by the master node into the library

Mysql > source absolute path\ xxxx.dmp

3) set master information

Mysql > chang master to

MASTER_HOST='192.168.10.11'

MASTER_USER='replication'

MASTER_PASSWORD='replication'

MASTER_PORT=3306

MASTER_LOG_FILE='node1-bin.000001'

MASTER_LOG_POS=154

MASTER_CONNECT_RETRY=10

4) start slave

Mysql > start slave

5) see the information of slave

Mysql > show slave status\ G

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.10.11

Master_User: replication

Master_Port: 3306

Connect_Retry: 60

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates

The message did not report an error, indicating that the configuration was successful.

4. Verification

Add, delete, modify, check and other operations in the master database to check the synchronization of the two slave libraries.

The above content is how to build the mysql5.7.15 master-slave replication environment. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, 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