linux下手动清除mysql日志的方法


1.手动清除日志前 请检查mysql设置文件

[root@localhost ~]vi /etc/my.cnf
如果
#log-bin=mysql-bin

#binlog_format=mixed
被注释掉,那么此时我们手动删除mysql日志时,会提示

mysql> show master logs;

ERROR 1381 (HY000): You are not using binary logging

未启用mysql二进制日志

此时我们需要将#log-bin 和#binlog_format的”#”取消掉,如下图所示:
[root@localhost ~]vi /etc/my.cnf
取消mysql日志设置

2.重新启动mysql
[root@localhost ~]service mysqld restart; //重启mysql



3.进入mysql

3.1 查询mysql安装目录
[root@localhost ~]# ps -ef|grep mysql //查询 mysql的安装目录
root 28475 1 0 09:53 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe –datadir=/usr/local/mysql/var –pid-file=/usr/local/mysql/var/iZ23ji6c7snZ.pid
mysql 28572 28475 0 09:53 pts/0 00:00:00 /usr/local/mysql/libexec/mysqld –basedir=/usr/local/mysql –datadir=/usr/local/mysql/var –user=mysql –log-error=/usr/local/mysql/var/iZ23ji6c7snZ.err –pid-file=/usr/local/mysql/var/iZ23ji6c7snZ.pid –socket=/tmp/mysql.sock –port=3306
————————-

/usr/local/mysql/var mysql数据存放路径
/usr/local/mysql/bin mysql的运行路径

3.2 进入mysql 运行路径
[root@localhost ~]cd /usr/local/mysql/bin
[root@localhost bin]./mysql -u root -p
enterpassword:*******;
mysql>show master logs; //注意分号是mysql标识每条命令完毕的标志,所以必须在每条命令后面加入分号
如下所示:
show master logs;
+——————+———–+
| Log_name | File_size |
+——————+———–+
| mysql-bin.000015 | 1059063 |
| mysql-bin.000016 | 205828775 |
| mysql-bin.000017 | 106 |
+——————+———–+
3 rows in set (0.00 sec)
show_master_logs

删除日志文件
mysql>purge master logs to ‘mysql-bin.000017’; //删除mysql “mysql-bin.000017″之前的日志文件
Query OK, 0 rows affected (0.05 sec)
purge_master_logs_to


4.重启mysql

[root@localhost ~]service mysqld restart;//重启mysql