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

Implementation of MySQL master-slave replication

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

Share

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

Principle of master-slave replication

1. The first part of the process is that master records binary logs. Master records these changes in the binary log before each transaction updates the data. MySQL writes transactions to the binary log. After the event is written to the binary log, master notifies the storage engine to commit the transaction. 2.slave copies master's Binary Log to its own Relay Log. First, slave starts a worker thread-- the Imax O thread. The iUnip O thread opens a normal connection on master and then starts binlog dump process. Binlog dump process reads events from master's binary log, and if master has been synchronized, it sleeps and waits for master to generate new events. The Icano thread writes these events to the Relay Log. 3.SQL slave thread (SQL from the thread) handles the last step of the process. SQL Thread reads events from the Relay Log and replays the events, updating the data in slave to make it consistent with the data in master. As long as the thread is consistent with the Ibank O thread, the Relay Log is usually in the cache of OS, so the overhead of Relay Log is small. Implement step environment firewall and selinux both turn off masterslaveIP192.168.7.71192.168.7.72 hostname master01slave01OSCentOS7CentOS7MySQL version 5.7.285.7.281. Install slightly 2.master configuration 2.1 to add the following to the my.cnf file, and then restart the database. # vim / etc/ my.cnf [mysqld] log-bin = mysql-binserver-id = restart the service systemctl start mysqld2.2 to create an authorized replication account grant replication slave on *. * to repluser@'192.168.7.%' identified by '123.composition2.3 View the binary log file name and position information mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +- -+ | mysql-bin.000001 | 154 | +- -+ 1 row in set (0.00 sec) 3.slave configuration 3.1 add the following to the my.cnf file Then restart the database. [mysqld] server-id = 2read_only = ON # is set to read-only, but is not valid for superusers. 3.2 execute the following command to specify the information to connect to the main service. Mysql > CHANGE MASTER TO-> MASTER_HOST='192.168.7.71',-> MASTER_USER='repluser',-> MASTER_PASSWORD='123.com',-> MASTER_PORT=3306,-> MASTER_LOG_FILE='mysql-bin.000001',-> MASTER_LOG_POS=154; Note: make sure that the MASTER_LOG_FILE matches the file and that the MASTER_LOG_POS matches the location returned by the previous SHOW MASTER STATUS. Start slavemysql > start slave;3.4 to check the status of I / O threads and SQL threads. If it is Yes, synchronization with the master server is successful. Mysql > show slave status\ gateway * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.7.71 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 154 Relay_Log_File: slave01-relay-bin.000002 Relay_Log_Pos: 320 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes... Omit information. 3.5 File master.info related to replication function: used to save relevant information when slave connects to master, such as account number, password, server address, etc. Relay-log.info: the correspondence between the current binary log and the local relay log log that has been replicated on the current slave node

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

Servers

Wechat

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

12
Report