Method: 1. Use the "RESET MASTER" and "RESET SLAVE" commands to delete binary logs; 2. Use the "PURGE BINARY LOGS" statement to delete binary logs; 3. Use the "mysqladmin flush-logs" command to delete more than Three days of binary logs.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
1. Use the RESET MASTER statement to delete the MySQL binary log
The Reset Master statement is used to replicate the Master and Slave servers. Start a new database during this period. This statement can be used to delete all binary logs.
Clean the binary logs on the Master server:
shell> mysql -u username -p mysql> RESET MASTER;
Clean the binary logs on the Slave server:
mysql -u username -p mysql> RESET SLAVE;
2. Use the PURGE BINARY LOGS statement to delete the MySQL binary logs
The PURGE BINARY LOGS statement can delete Binary Log based on date or up to Binary Log sequence number.
Based on the binary log example shown above, I would like to delete binaries up to mysql-bin.000015 (retained):
shell> mysql -u username -p mysql>PURGE BINARY LOGS TO 'mysql-bin.000015';
Alternatively, you can delete binaries older than a specific date:
shell> mysql -u username -p mysql> PURGE BINARY LOGS BEFORE '2009-05-01 00:00:00';
3. Use the mysqladmin flush-logs command to delete MySQL Binary Log
Another method is to run the mysqladmin flush-logs command, which will delete the logs older than 3 days. Binary log.
shell> mysqladmin -u username -p flush-logs
Recommended learning: mysql video tutorial
The above is the detailed content of How to delete mysql binary log. For more information, please follow other related articles on the PHP Chinese website!