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 Mysql master-slave synchronization in Centos7 system

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

What this article shares to you is about how to configure Mysql master-slave synchronization in the Centos7 system, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

(1) first of all, make sure that there are two devices (master and slave) and install the Mysql database on the two devices. After installation is complete

Use mysql-u [database user name]-p [user password]. If you can log in to mysql, the installation is successful.

(2) Edit the mysql configuration file, which is usually / etc/mysql/mysql.conf.d/mysqld.cnf (the directory specified by the user when installing Mysql

Such as / etc/my.conf, etc.). Add the following under the [mysqld] module in the master and slave mysql as required:

[mysqld] default-storage-engine=innodb innodb_file_per_table=1 collation-server=uft8_general_ci init-connect='SET NAMES uft8' bind-address=0.0.0.0 log_bin=mysql-bin relay_log=mysql-relay-bin expire_logs_days=100 skip-slave-start=1 binlog_do_db= [database name to be synchronized] binlog-ignore-db=mysql,sys,information_schema,performance_schema server-id= [main fill in 1 From filling in 2] auto-increment-increment=2 auto-increment-offset=1 open_files_limit=65535 mac_connections=1000 slave-skip-errors=all

(3) shell connects to the master and slave servers, mysql-u [database user name]-p [user password], log in to the master node and slave node mysql, respectively, and create a synchronous user repl, and execute the following command:

Grant all privileges on *. * to 'repl'@'%' identified by' repl' with grant option

Then exit exits the Mysql operation page and restarts the Mysql service with the following command:

Systemctl restart mysql.service

Then go to the primary node Mysql and view the File column and Positon column of Mysql. Execute command: show master status; appears and the result is as follows

(4) Log in to the slave server, mysql-u [database user name]-p [user password] enter Mysql and execute:

Stop slave; reset slave; change master to master_host=' [primary node IP]', master_user='repl',master_password='repl',master_log_file=' [mysql-bin.000001, File column in reference (3)]', master_log_pos= [Postion column in reference (3)]; exit

Execute systemctl restart mysql.service to restart the Mysql service.

(5) start the slave slave library and enter the slave node Mysql from mysql-u [Database user name]-p [user password] and execute the following command:

Start slave

Execute: show slave status\ G; check the backup service status. If the following two states are Yes, the master-slave synchronization is successful.

Next, you can try to insert a piece of data into the main database to see if it is enough to automatically add it from the database. Isn't that a little exciting? Let's test it.

PS: what if there is a problem of not synchronizing?

(1) Please check whether the Master_Log_File attribute and Read_Master_Log_Pos attribute in the above figure are consistent with the query results of the master node.

(2) it may be the timeout of connecting to the master database from the database. Go ahead and change the connection delay a little bit.

(3) if the above cannot be solved, please check the mysql log to find out the reason.

The above is how to configure Mysql master-slave synchronization in the Centos7 system. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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