MySQL master/slave replication, semi-synchronous replication, bitsCN.com
Mysql master-slave and master-slave replication
Mysql master-slave and master-slave replication
I. INTRODUCTION to replication
MySQL supports one-way and asynchronous replication. one server acts as the master server during the replication process, and one or more other servers
Act as the slave server. The master server writes updates to the binary log file and maintains an index of the file to track log loops.
These logs can record updates sent to the slave server. When a slave server connects to the master server, it notifies the master server
Location of the last successful update read by the server in the log. The slave server receives any updates from then on, and then
Block and wait for the master server to notify you of new updates.
Note that when you perform a copy, all updates to the tables in the copy must be performed on the master server. Otherwise, you must be careful,
To avoid conflicts between updates to tables on the master server and those on the slave server.
Unidirectional replication facilitates robustness, speed, and system management:
L The Master server/slave server settings increase robustness. When a problem occurs on the master server, you can switch to the slave server
Copies.
L better customer response time can be obtained by splitting the customer query load between the master server and slave server.
SELECT queries can be sent to the slave server to reduce the query processing load of the master server. However, the statement for modifying data is still
It should be sent to the master server for synchronization between the master server and the slave server. If the query is not updated, the load is
The balance policy is effective, but is generally used to update queries.
L Another advantage of using replication is that one slave server can be used for backup without interfering with the master server. In the backup
During the process, the master server can continue to process updates.
MySQL provides the database synchronization function, which enables database redundancy, backup, recovery, and load balancing.
Very helpful
MySQL uses three threads to execute the replication function (one of them is on the master server and the other two are on the slave server. When issued
When you start slave, create an I/O thread from the server to connect to the master server and send binary logs to the master server.
The master server creates a thread to send the binary log content to the slave server. Read Master services from server I/O threads
The Binlog Dump thread sends the content and copies the data to a local file in the data directory of the server.
Logs. The first thread is an SQL thread. the server uses this thread to read relay logs and execute updates contained in the logs.
The show processlist statement can be used to query information about replication on the master server and slave server.
The default relay log uses a file name in host_name-relay-bin.nnnnnn format, where host_name is from the service
Host name. nnnnnn is the serial number. Create a continuous relay log file with a continuous serial number, starting from 000001. Slave server
The server tracks relay log index files to identify currently used relay logs. The default relay log index file name is
Host_name-relay-bin.index. By default, these files are created in the data directory of the slave server. Relay day
Logs are in the same format as binary logs and can be read using mysqlbinlog. When the SQL thread completes the relay log
After all events, relay logs are automatically deleted.
The slave server creates two other state files in the data directory.