Because of business needs, I want to clean up some data in the mysql master database, but the slave database wants to keep it. According to the introduction of netizens, you can skip the cleanup command according to the binlog
.
; --Refresh the log, switch to a new binlog log, it is relatively small, it will be more convenient to modify it later
Query OK, 0 rows affected (0.21 sec)
mysql> show master status \G
*********** **************** 1. row ****************************
File: mysql- bin.000039 -- The binlog location here will not be used later
Position:
33958 Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.03 sec)
2. Stop synchronization from the library --- Step 1.2 Try to operate
mysql> stop as quickly as possible slave;
Query OK, 0 rows affected (0.05 sec)
mysql> show slave status \G
**************************** 1. row * ****************************
Slave_IO_State:
Master_Host: 192.168.1.196
Master_User: repli
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000039
Read_Master_Log_Pos: 488906
Relay_Log_File: mysql-relay-bin.000016
Relay_Log_Pos: 489119
Relay_Master_Log_File: mysql-bin.000039
Slave_IO_Running: No
Slave_SQL_Running: No
3.主库清空数据
mysql> truncate table t2; 步骤a
Query OK, 0 rows affected (0.46 sec)
mysql> show master status \g 步骤b
+-------+----------+--------------+---- --------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+--- ---------------+------------+--------------+-------- ----------+-------------------+
| mysql-bin.000039 | 1942762 | | | |
+------ ------------+------------+--------------+------------ -------+-------------------+
1 row in set (0.06 sec)
/usr/local/mysql/bin/mysqlbinlog mysql-bin. 000039 >000039.sql Step c
4. Edit 000039.sql, delete the truncate statement
truncate table t2 /*!*/; ---Deleted content
Search 1942762 If you can't find the location, you may lose data, so the previous The three-step abc must pay attention to the order! It is best to include this location information in the sql, and then delete the following content to avoid repeated operations when the log is applied later.
end_log_pos 1942762 Kill everything after this position!
5. Restore
/usr/local/mysql/bin/mysql -umydba -p
source /root/000039.sql
mysql> change master to master_log_file='mysql-bin.000039', master_log_pos=1942762;
Query OK, 0 rows affected (0.19 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status \G
************************ **** 1. row ****************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.196
Master_User: repli
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000039
Read_Master_Log_Pos: 10009221
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 8066779
Relay_Master_Log_File: mysql-bin.000039
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 10009221
Relay_Log_Space: 8066986
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
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
Master_UUID: 701cbadc-ba33-11e5-9091-305a3a78baf2
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
---Master-slave synchronization, skip the truncate command
6. Verify
master library:
mysql> select * from t2;
Empty set (0.00 sec)
slave library:
mysql> select * from t2;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+----+
5 rows in set (0.00 sec)
MySQL master database cleans data and keeps slave database
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327013757&siteId=291194637
Recommended
Ranking