Go to blog. csdn. netm582445672articledetails7731565 operating system environment: CentOS5.51.MySQL Master/Slave process. mySQL Master/Slave description. the master server must enable binary log files. b. 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
To http://blog.csdn.net/m582445672/article/details/7731565 operating system environment: CentOS5.5 1. mySQL master-slave flowchart 2. mySQL Master/Slave description. the master server must enable binary log files. b. 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
Transfer http://blog.csdn.net/m582445672/article/details/7731565
Operating System Environment: CentOS5.5
1. MySQL master-slave Flowchart
2. MySQL Master/Slave description
A. The master server must enable the binary log file.
B. 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 start slave is issued, an I/O thread is created from the server to connect to the master server and send statements recorded in its binary log. The master server creates a thread to send the binary log content to the slave server. This thread can identify the Binlog Dump thread in the output of show processlist on the master server. Read the content sent by the Binlog Dump thread of the master server from the server I/O thread and copy the data to a local file in the data directory of the slave server, that isRelay log. The first thread is an SQL thread, which is created from the server to read relay logs and execute updates contained in logs.
3. host information
Mysql (master): 192.168.96.12
Mysql (standby): 192.168.96.2
4. Install mysql on the host and backup machine
The installation of mysql5.5 source code is used here.
For details about the installation process, see install mysql5.5 in the source code of centos 5.5.
Address: http://blog.csdn.net/m582445672/article/details/7649999
5. Configure the my. cnf file on the host.
[Mysqld]
Server-id = 1 # unique Service Identifier
Log-bin = mysql-bin # enable binary log. The default path is data /.
Binlog_format = mixed # binary file format
# There are three formats
# Binlog_format = statement write the SQL statement entered by the master database directly into the binary file
# Binlog_format = row: Write the row modified by the master database to the binary file
# Binlog_format = mixed mode
# For Data Replication of stored procedures, functions, triggers, and events in different binary formats, see
Mysql5.5 master-slave replication (triggers, functions, storage engines, and event processing) Description
# Address: http://blog.csdn.net/m582445672/article/details/7670802
#============ The following parameters, in this experiment, not Configured ======================================================== =
Replicate-do-db = test # the database to be copied (in this test, I don't need this parameter)
Replicate-ignore-db = mysq # databases that do not need to be copied (in this experiment, I don't need this parameter)
Replicate-ignore-db = information_schema # databases that do not need to be copied (in this experiment, I don't need this parameter)
# If the replicate-do-db and replicate-ignore-db parameters are not used, all databases are copied.
#===================================================== ========================================================== =====
Start mysql (master)
6. Add a replication account to the master database.
Grant replication slave on *. * to 'mark' @ '%' identified by 'mark' with grant option;
7. Configure the my. cnf file for the backup server
Server-id = 2 # change to 2.
Start mysql (standby)
#=== The following is only an explanation, not included in this experiment ====================================== ====
Of course, binary files can also be enabled on the slave machine. However, by default, the data copied from the master database is not written into the binary files of the slave database.
Therefore, if you want to copy A --> B --> C, logs-slave-updates = 1 is required.
[Mysqld]
Log-bin = mysql-bin
Binlog_format = mixed
Logs-slave-updates = 1
#===================================================== ====================================
8. The slave machine connects to the host.
A. Check the binary location of the current host first.
Mysql> show master status;
B. run commands on the slave machine to connect to the host
Mysql> change master to master_host = "192.168.96.12", master_port = 3306, master_user = "mark", master_password = "mark", master_log_file = "mysql-bin.000004", master_log_pos = 107, master_connect_retry = 10;
C. Start the I/O thread and SQL thread on the slave machine.
Mysql> start slave;
D. Check the Master/Slave status on the slave machine.
Mysql> show slave status \ G
9. Test master-slave Replication
Create an alex database on the host.
Host:
SLAVE:
Here, the master-slave configuration is complete.
10. Master-slave replication of several important files
A.master.info
Used to record which server, account, and password to connect
It also records which binary files are copied to the master server and where the binary files are copied.
The IO thread from the server will first put all the data copied from the master service into the relay-log.info.
And record the copied location. IO thread only copies
For the remaining lines, go to the official documents for details.
B .relay-log.info
This is the log of the slave server, which records the amount of data written to the slave service.
./Ip_lb-relay-bin.000002 # relay log location
336 # copy a row
Mysql_bin.000004 # Name of the binary log file corresponding to the master server in the relay log
190 # location
Note: if an error occurs when copying a sentence, the subsequent binary SQL statement will not continue to be copied.
Mysql_bin.000004 190 will be recorded in the relay log.
The SQL thread reads the information in the forward log, which is recorded by the relay-log.info information.
11. copy information from the server
Mysql> show slave status \ G
[Plain]View plaincopyprint?
- * *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event # The state of the IO thread
- Master_Host: 192.168.96.12 # link the IP address of the master server
- Master_User: mark # master server user name
- Master_Port: 3306 # master server password
- Connect_Retry: 10 # How many seconds will the connection be reconnected after the master and slave nodes are disconnected?
- Master_Log_File: mysql-bin.000004 # Name of the master server binary log file currently read from the server I/O thread
- Read_Master_Log_Pos: 190 # start point of the position read from the server I/O thread from the binary log of the current master server.
- Relay_Log_File: ip_lb-relay-bin.000002 # Name of the relay log file currently read and executed from the server SQL thread
- Relay_Log_Pos: 336 # start point of the position where the SQL thread currently reads execution from the relay log.
- Relay_Master_Log_File: mysql-bin.000004 # location of the statement being executed from the SQL process in the server
- Slave_IO_Running: Yes # Whether to enable the IO thread running from the server
- Slave_ SQL _Running: Yes # Whether to enable the SQL thread running from the server
- Replicate_Do_DB: # Name of the database for master-slave Replication
- Replicate_Ignore_DB: # Name of the master database that never needs to be copied
- Replicate_Do_Table: # Master-slave table
- Replicate_Ignore_Table: # tables that never need to be copied
- Replicate_Wild_Do_Table: # tables that can be copied across Databases
- Replicate_Wild_Ignore_Table: # tables that cannot be copied across Databases
- Last_Errno: 0 # The Last copied error code... 0 indicates no error
- Last_Error: # Last copied error message
- Skip_Counter: 0 # recently used SQL _SLAVE_SKIP_COUNTER value. (This value indicates how many skipped events are being executed in SQL)
- Exec_Master_Log_Pos: 190 # Where the SQL thread executes the log-binfile on the master server. If this value is the same as Read_Master_Log_Pos, it can be proved
- Relay_Log_Space: 492 # total size of all original relay logs.
- Until_Condition: None # value specified in the UNTIL clause of the start slave statement
- Until_Log_File: # value specified in the UNTIL clause of the start slave statement
- Until_Log_Pos: 0 # value specified in the UNTIL clause of the start slave statement
- Master_SSL_Allowed: No # these fields show the parameters used by the slave server. These parameters are used to connect to the master server.
- Master_SSL_CA_File:
- Master_SSL_CA_Path:
- Master_SSL_Cert:
- Master_SSL_Cipher:
- Master_SSL_Key:
- Seconds_Behind_Master: 0 # This field indicates the number of slave servers that are "behind. When the subordinate SQL thread is running (processing updates ),
- # This field indicates the start time of the most recent event executed by the thread on the master server, and the number of seconds has elapsed.
- # This field is zero when this thread is caught by the slave server I/O thread and enters the idle state, waiting for more events from the I/O thread.
- # In short, this field measures the time gap between the SQL thread of the slave server and the I/O thread of the slave server, measured in seconds.
- # If the network connection between the master server and the slave server is fast, the slave server I/O thread is very close to the master server,
- # This field can be very similar to the number of SQL threads on the slave server that are behind the master server.
- # This indicator is inaccurate if the network is slow. The dependent SQL thread often catches up with the slow reading speed of the dependent server I/O thread,
- # Therefore, the value of Seconds_Behind_Master is usually 0. This is true even when I/O threads lag behind the master server.
- # In other words, this column is only useful for fast networks.
- # Even if the master server and slave server do not have the same clock, the time difference calculation will also take effect (when the slave server I/O thread starts, the time difference is calculated. And assume that the time difference remains unchanged from now on ).
- # If the slave SQL thread does not run, or if the slave server I/O thread does not run or is not connected to the master server,
- # Seconds_Behind_Master is NULL (meaning "unknown ").
- # For example, if the slave server I/O thread sleep for master-connect-retry seconds before the connection is reconnected, NULL is displayed,
- # Because the slave server does not know what the master server is doing, it cannot be sure how much it lags behind.
- Master_SSL_Verify_Server_Cert: No
- Last_IO_Errno: 0
- Last_IO_Error:
- Last_ SQL _Errno: 0
- Last_ SQL _Error:
- Replicate_Ignore_Server_Ids:
- Master_Server_Id: 1
- 1 row in set (0.00 sec)
* *************************** 1. row *************************** Slave_IO_State: waiting for master to send event # state of the IO thread Master_Host: 192.168.96.12 # Link master server IP Master_User: mark # master Server Username Master_Port: 3306 # master server password Connect_Retry: 10 # How many seconds after master-slave disconnection re-link Master_Log_File: mysql-bin.000004 # Name of the master server binary log file currently read from the server I/O thread Read_Master_Log_Pos: 190 # start point of the location where the I/O thread of the slave server reads binary logs from the current master server. Relay_Log_File: ip_lb-relay-bin.000002 # Name of the relay log file currently read and executed from the server SQL thread Relay_Log_Pos: 336 # start point of the position where the current relay log is read from the relay log from the server SQL thread. Relay_Master_Log_File: mysql-bin.000004 # position of the statement being executed in the SQL process on the server Slave_IO_Running: Yes # Whether to enable Slave_ SQL _Running: yes # Whether to enable Replicate_Do_DB when running the SQL thread on the server: # Replicate_Ignore_DB: # Replicate_Do_Table name of the master database that never needs to be copied: # Replicate_Ignore_Table: # Replicate_Wild_Do_Table: # Replicate_Wild_Ignore_Table: # Last_Errno: 0 # the last copy Error Code cannot be copied across databases... 0 indicates no error Last_Error: # Last copied error message Skip_Counter: 0 # recently used SQL _SLAVE_SKIP_COUNTER value. (This value indicates the number of skipped events to execute the SQL statement.) Exec_Master_Log_Pos: 190 # the location where the SQL thread executes the log-binfile on the master server. if the value is the same as Read_Master_Log_Pos. it can be proved that the total size of all the original relay logs combined by Relay_Log_Space: 492. Until_Condition: None # value specified in the UNTIL clause of the start slave statement Until_Log_File: # value specified in the UNTIL clause of the start slave statement Until_Log_Pos: 0 # The value Master_SSL_Allowed: No # specified in the UNTIL clause of the start slave statement shows the parameters used by the SLAVE server. These parameters are used to connect to the master server. Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 # This field indicates the number of slave servers falling behind. When the subordinate SQL thread is running (processing updates), # This field starts with the time mark of the most recent event executed by this thread on the master server, and has elapsed in seconds. # This field is zero when this thread is caught by the slave server I/O thread and enters the idle state, waiting for more events from the I/O thread. # In short, this field measures the time gap between the SQL thread of the slave server and the I/O thread of the slave server, measured in seconds. # If the network connection between the master server and the slave server is fast, the slave server I/O thread will be very close to the master server. # This field can be very similar to that of the slave server, the number of SQL threads on the slave server lags behind that on the master server. # If the network is slow, this indicator is inaccurate. The slave SQL thread often catches up with the slave server I/O thread with slow reading speed. # therefore, Seconds_Behind_Master often displays a value of 0. This is true even when I/O threads lag behind the master server. # In other words, this column is only useful for fast networks. # Even if the master server and slave server do not have the same clock, the time difference calculation will also take effect (when the slave server I/O thread starts, the time difference is calculated. And assume that the time difference remains unchanged from now on ). # If the slave SQL thread does not run, or if the slave server I/O thread does not run or is not connected to the master server, # Seconds_Behind_Master is NULL (meaning "unknown "). # For example, if the slave server I/O thread sleep for master-connect-retry seconds before the connection is reconnected, NULL is displayed, # Because the slave server does not know what the master server is doing, it cannot be sure how much it lags behind. Failed: No Last_IO_Errno: 0 Last_IO_Error: Last_ SQL _Errno: 0 Last_ SQL _Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 row in set (0.00 sec)