In mysql, you can use the purge command to clear logs. This command is used to clear specified data. The syntax is "purge binary logs to 'mysql-tb-bin.000005';".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
The binary log and .log log of Mysql are opened. These log files are very large. The .log log has reached 25 G, mysql-bin.00000X log It has also reached 5 G. First clean up the log files on the main server. I first clean up the binary file (mysql-bin.00000X) and first check what files are there:
Use the command to view:
show binary logs;
Then check which binary is being used from the server,
show slave status\G;
We see the log of mysql-tb-bin.000005 The file is in use.
Go back to the main server and start cleaning the logs, but the log file mysql-tb-bin.000005 cannot be cleaned. Use the command to clean:
purge binary logs to 'mysql-tb-bin.000005';
This command is to clean up mysql-tb-bin. Other binary logs other than 000005; after successful execution, check the binary log list: show binary logs;
The cleanup is successful, but manual cleanup is very dangerous and relatively It’s complicated. Is there any way to automatically clean it up? The answer is yes, add this configuration in my.ini: expire_logs_days=5 This configuration means that the number of days for the log to expire, if the log is more than 5 days old, mysql will automatically clean up the logs older than 5 days, so you don’t have to worry about it anymore There is a problem of log files getting bigger and bigger. You must be careful when executing commands to ensure that everything is safe before executing them.
Recommended learning: mysql video tutorial
The above is the detailed content of How to clear logs in mysql. For more information, please follow other related articles on the PHP Chinese website!