mysql开启binlog后会在/var/lib/mysql下创建binlog文件,如果手工删除,则下次mysql启动会报错:
mysqld: File './master-bin.000001' not found (Errcode: 2 - No such file or directory)
2019-02-16T17:00:08.484461Z 0 [ERROR] Failed to open log (file './master-bin.000001', errno 2)
2019-02-16T17:00:08.484464Z 0 [ERROR] Could not open log file
正确的删除方法是:
mysql> show binary logs;
+-------------------+------------+
| Log_name | File_size |
+-------------------+------------+
| master-bin.000027 | 43442 |
| master-bin.000028 | 7573 |
| master-bin.000029 | 371919 |
+-------------------+------------+
29 rows in set (0.00 sec)mysql> purge binary logs to 'master-bin.000029';
Query OK, 0 rows affected, 10 warnings (0.18 sec)mysql> show binary logs;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| master-bin.000029 | 696322 |
+-------------------+-----------+
1 row in set (0.00 sec)
另外也可以在配置文件中配置过期时间
# vi /etc/mysql/my.cnf
expire_logs_days = 7mysql> reset master;