Delete/Clean MySQL's /var/lib/mysql

question

Through the investigation, it  /var/lib/mysql was found that a large number of  binlog.xxxxxxx files were found under the path, and they occupied hundreds of GB of disk space.

reason

binlog It is a binary log that records all database table structure changes (such as CREATE, ALTER TABLE...) and table data modifications (INSERT, UPDATE, DELETE...).

binlog Operations such as SELECT and SHOW will not be recorded, because such operations do not modify the data itself, but you can view all statements executed by MySQL by querying the general log.

Binary logs include two types of files: binary log index files (file name suffix  .index) are used to record all binary files, and binary log files (file name suffix  .00000*) record all DDL and DML (except data query statements) statement events of the database.

So simply describe it,  写操作 the more databases, the more frequent, binlog the more records, and even what the author encountered  爆炸增长.

solve

Since  binlog it is a log, just make sure (or "pretend to make sure") that the past operations are correct, and we don't have any  从 binlog 恢复数据 needs, so delete it.

delete manually

Directly  /var/lib/mysql under the path, it will  binlog.0* be deleted (be careful not to delete  binlog.index)

This method is not recommended, because manual deletion will not update  binlog.index, but  binlog.index the effect is to speed up  binlog the speed of finding files.

Delete the binlog before the specified number

mysql> PURGE MASTER LOGS TO 'binlog.000860';
Query OK, 0 rows affected (0.01 sec)

Delete the binlog before the specified date

mysql> PURGE MASTER LOGS BEFORE '2020-11-11 11:11:11';
Query OK, 0 rows affected (0.19 sec)

Clear all binlogs

mysql> RESET MASTER;
Query OK, 0 rows affected (0.09 sec)

Configure automatic cleanup

mysql> set global expire_logs_days=7;

binlog Only files within 7 days will be kept  .

Or modify  MySQL the configuration file, set  expire_logs_days=7 and then restart the service, it will take effect permanently.

Guess you like

Origin blog.csdn.net/qq_41210783/article/details/127072154