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

Configuration method of separating Master from Slave in MySQL

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

Share

Shulou(Shulou.com)06/01 Report--

This article mainly gives you a brief introduction to the configuration method of MySQL master-slave separation. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here. Let's go straight to the topic. I hope this article on the configuration method of MySQL master-slave separation can bring you some practical help.

1. Introduction

MySQL database sets read-write separation, which enables write and read operations on the database to be performed on different CVMs, improving concurrency and response speed. Today's websites are generally larger, with database master-slave separation and read-write separation, which can not only play the role of backup but also reduce the pressure of reading and writing of the database. I have heard of these all the time, but I have never put them into practice. Today I have time to practice and record the process.

2. Environmental preparation

I have prepared two CVMs, one is local PC and the other is remote CVM. I will not introduce the installation of Mysql database MySQL on the two machines. It should be noted here that the version of MySQL installation had better be consistent. If it is inconsistent, there may be problems when reading the low version to the higher version, and it is best to keep it consistent.

Main library master CVM: 172.10.10.69 centos 7 Linux system, mysql version 5.6.35

Slave slave Native: 172.10.10.240 Win7 system, mysql version 5.6.35

3. Configuration of the main library

Create a user root in the main library to read the execution log of the main library from the library.

It needs to be executed on the mysql command line. You need to log in to the command line first.

1. GRANT REPLICATION SLAVE ON. * TO 'root'@'192.10.10.240' IDENTIFIED BY' 123456; 2. Flush privileges

Modify the my.cnf file:

Add under [mysqld]

Server-id=13log-bin=master-binlog-bin-index=master-bin.index

Restart MySQL

Enter the mysql command line and enter show master status; to view the information

Remember File and Position, because they are used when configuring the slave service.

4. Configure slave CVM

Modify my.cnf

Server-id=2relay-log=slave-relay-binrelay-log-index=slave-relay-bin.index

Restart the database.

Connect to the master database and enter the command on the command line:

Change master to master_host='192.10.10.69', # Master CVM Ipmaster_port=3306,master_user='root',master_password='123456', master_log_file='master-bin.000255', # Master log file name master_log_pos=1575; # Master log synchronization start location

Pay attention to whether the execution is successful, and if the execution fails, check the code to see what went wrong.

If the execution is normal, launch the slave library slave and check the connection status.

/ / need to execute start slave; show slave status; on the mysql command line / / check the slave connection status

Status information:

Slave_IO_State: Waiting for master to send event Master_Host: 45.78.57.4 Master_User: test Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 672913 Relay_Log_File: slave-relay-bin.000044 Relay_Log_Pos: 504 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes / / must be YES Slave_SQL_Running: Yes / / must be YES

If Slave_IO_Running and Salve_SQL_Running are not YES at the same time, then the configuration is wrong, check the above steps.

5. Test

Add a piece of data to the master database to see if there is any data from the database.

MySQL master-slave separation configuration method will first tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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