mysql 删除bin_log

例行检查服务器,发现磁盘空间异常,du -sh发现/usr/local/mysql/var下面有近2G的空间被MySQL Binary Log文件占用,那就清除它们。
mysql -u root -p 先登录

mysql> show binary logs;
+——————+———–+
| Log_name         | File_size |
+——————+———–+
| mysql-bin.000001 |     19099 |
| mysql-bin.000002 |    714954 |
| mysql-bin.000003 |       263 |
| mysql-bin.000004 |       125 |
| mysql-bin.000005 |   7678507 |
| mysql-bin.000006 |     54963 |
| mysql-bin.000007 |   1327716 |
| mysql-bin.000008 |   1785051 |
| mysql-bin.000009 |  14897541 |
| mysql-bin.000010 | 320912902 |
| mysql-bin.000011 |       125 |
| mysql-bin.000012 | 147692096 |
| mysql-bin.000013 |  19483104 |
| mysql-bin.000014 |   2406374 |
| mysql-bin.000015 |   1018655 |
| mysql-bin.000016 | 408539355 |
+——————+———–+
16 rows in set (0.00 sec)

mysql> purge binary logs before '2011-1-19 23:00:00';
Query OK, 0 rows affected (1.25 sec)

mysql> show binary logs;
+——————+———–+
| Log_name         | File_size |
+——————+———–+
| mysql-bin.000016 | 408557560 |
+——————+———–+
1 row in set (0.00 sec)
OK,清空了日志。
然后禁用日志功能,去/etc/my.cnf注释掉图示的两行:

点击查看原图

purge的语法:
PURGE { BINARY | MASTER } LOGS
    { TO 'log_name' | BEFORE datetime_expr }

The binary log is a set of files that contain information about data modifications made by the MySQL server. The log consists of a set of binary log files, plus an index file.

Examples:

PURGE BINARY LOGS TO 'mysql-bin.010';
purge binary logs before '2011-1-19 23:00:00';

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注