MySQL master-slave data construction problem processing

If it is slave_io_running no, then I personally see three situations. One is that there is a problem with the network and cannot be connected. For example, once I used a virtual machine to build replication and used the nat network structure, even if I died, I could not connect. The second is that there may be a problem with my.cnf. I will not say how to write the configuration file. There are too many online. The last one is the problem of authorization. Replication slave and file permissions are necessary. If you are not afraid of death then all. .

Once io is no, first look at the err log to see what is wrong. It may be the network, or it may be that the packet is too large to receive. At this time, change the parameter max_allowed_packet on the active and standby.

If it is slave_sql_running no, then there are two possibilities. One is that there are other write operations in this table on the slave machine, that is, the program is written. This will be a problem. I want to reproduce it today, but sometimes There is a problem, sometimes there is no problem. It is not too clear now. I will update it later. Another possibility is that the slave process restarts and the transaction is rolled back. This is also a self-protection measure of mysql. Like read-only when critical.

If you want to recover at this time, just stop the slave, set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; and then open the slave again.
=========================================================================
Slave_SQL_Running: No mysql synchronization troubleshooting
     Check the database today and find that a MySQL Slave is not synchronized with the host, check the Slave status:
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: No
Last_Errno: 1062
....
Seconds_Behind_Master: NULL
Reason:
1. The program may be running on the slave Write operation 2. It may also be caused by the transaction rollback after the slave machine restarts.  
Solution I:
1. First stop the Slave service: slave stop
2. Check the host status on the main server:
record the values ​​corresponding to File and Position.
mysql> show master status;
+------------------+------------+------------ --+-----------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------ +------------+---------------+------------------+
| mysql- bin.000020 | 135617781 | | |
+------------------+-----------+---------- ----+--------------------------------+
1 row in set (0.00 sec)
3. Perform manual synchronization on the slave server:
mysql> change master to > master_host='master_ip', > master_user='user', > master_password='pwd', > master_port=3307, > master_log_file='mysql-bin.000020 ', > master_log_pos=135617781; 1 row in set (0.00 sec) mysql> slave start; 1 row in set (0.00 sec) Check the slave status again and find: Slave_IO_Running: Yes Slave_SQL_Running: Yes ... Seconds_Behind_Master: 0  

 
 
 
 








Solution II:
mysql> slave stop;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;
 
My own experience: The first method is to force the synchronization from a certain point, and some unsynchronized data will be lost. The subsequent deletion of records on the main server will also cause some error messages, which will not affect the use. Method 2 may not effective.
 
 
=======================================================================================]
1, the master and slave cannot be synchronized:
show slave status;报错:Error xxx dosn't exist
且show slave status\G:
Slave_SQL_Running: NO
Seconds_Behind_Master: NULL
解决方法:
stop slave;
set global sql_slave_skip_counter =1 ;
start slave;
After that, the slave will synchronize with the master mainly to see:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Whether Seconds_Behind_Master is 0, 0 is already synchronized
2. Some optimization and monitoring that need to be done:
show full processlist; //View the current synchronization thread number of mysql
skip-name-resolve //Skip dns name query, which helps to speed up connection and synchronization
max_connections=1000 // Increase the number of Mysql connections, (default 100)
max_connect_errors=100 //Increase the number of Mysql error connections, (default 10)
 

Check the log with some commands
1, show master status\G;
           here is mainly to see if the log-bin files are the same.
    show slave status\G;
    here is mainly to see:
                   Slave_IO_Running=Yes
                   Slave_SQL_Running=Yes
   If both are Yes, the configuration is successful.
2,在master上输入show processlist\G;
     mysql> SHOW PROCESSLIST\G
     *************************** 1. row ***************************
       Id: 2
       User: root
       Host: localhost:32931
       db: NULL
       Command: Binlog Dump
       Time: 94
       State: Has sent all binlog to slave; waiting for binlog to
         be updated
       Info: NULL
   If Command: Binlog Dump appears, the configuration is successful.
 
 
stop slave #Stop synchronization start slave #Start synchronization and start updating from where the log ends. SET SQL_LOG_BIN=0|1 #Host-side operation, requires super permission, used to start and stop the log, start and stop at will, it will cause inconsistent data between the host and the slave, resulting in errors SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n # The client is running, used to skip a few An event that can only be executed when the synchronization process stops with an error. RESET MASTER #Run on the host side, clear all logs, this command is the original FLUSH MASTER RESET SLAVE #Run on the slave machine, clear the log synchronization position flag, and regenerate master.info Although master.info is regenerated, it does not To use, it is best to restart the mysql process of the slave machine, LOAD TABLE tblname FROM MASTER #Slave run, reread the data of the specified table from the host side, only one can be read at a time, limited by the timeout time, you need to adjust the timeout time. Executing this command requires that the synchronization account has reload and super permissions. And have select permission on the corresponding library. If the table is relatively large, increase the value of net_read_timeout and net_write_timeout LOAD DATA FROM MASTER #Slave execution, re-read all data from the host side. Executing this command requires that the synchronization account has reload and super permissions. And have select permission on the corresponding library. If the table is relatively large, increase the value of net_read_timeout and net_write_timeout  
 
 
 
 

 
 
 
CHANGE MASTER TO master_def_list #Change some host settings online, multiple separated by commas, such as
CHANGE MASTER TO
  MASTER_HOST='master2.mycompany.com',
  MASTER_USER='replication',
  MASTER_PASSWORD='bigs3cret' MASTER_POS_WAIT() #Slave running SHOW MASTER STATUS #The host is running, see the log export information SHOW SLAVE HOSTS #The host is running, see the status of the connected slaves. SHOW SLAVE STATUS (slave) SHOW MASTER LOGS (master) SHOW BINLOG EVENTS [ IN 'logname' ] [ FROM pos ] [ LIMIT [offset,] rows ] PURGE [MASTER] LOGS TO 'logname' ; PURGE [MASTER] LOGS BEFORE ' date'  
 
 
 
 
 
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326625275&siteId=291194637