Home > Database > Mysql Tutorial > How to clear logs in mysql

How to clear logs in mysql

WBOY
Release: 2022-02-24 11:30:34
Original
10287 people have browsed it

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';".

How to clear logs in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to clear mysql logs

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;
Copy after login

How to clear logs in mysql

Then check which binary is being used from the server,

show  slave status\G;
Copy after login

How to clear logs in mysql

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';
Copy after login

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;

How to clear logs in mysql

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template