mysql删除binlog日志

1、 开启bin-log日志
[root@Oldboy ~]# grep "log-bin" /etc/my.cnf 
log-bin=mysql-bin
2、 查看bin-log日志是否开启
mysql> show variables like '%log_bin%';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| log_bin                         | ON                   |                   #记录binlog的开关,ON表示开启
| log_bin_trust_function_creators | OFF   |
| sql_log_bin                     | ON                 |                   #临时不记录binlog开关(增量恢复)
+---------------------------------+-------+
3 rows in set (0.00 sec)
3、查看当前mysql正在使用的binlog日志,这里的binlog日志千万不能删(主从库都要看)
mysql> show master status;
+------------------+-----------+--------------+------------------+-------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+-----------+--------------+------------------+-------------------+
| mysql-bin.000106 | 925450924 |              |                  |                   |
+------------------+-----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
4、删除binlog日志2种方法(亲测有效,删除之前先做个备份)
(1) 通过修改配置文件删除(需要重启mysql)
# vi /etc/my.cnf
expire_logs_days = 30  #保留最近30天的bin-log日志
 
#重启后查看mysql配置是否生效(或查看/mysql/data/目录下的mysql-bin.00* 是否只有30天的)
mysql> show variables like "expire_logs_days";
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| expire_logs_days | 30    |
+------------------+-------+
1 row in set (0.00 sec)

(2) 直接通过命令删除(无需重启mysql直接生效)
#登录mysql
[root@jxq-c2-16-10 mysql]# mysql -uroot -p 

#删除mysql-bin.000064之前的所有binlog日志(不包括'mysql-bin.000004')
mysql> purge binary logs to 'mysql-bin.000004';       #当前正在使用的binlog千万不能删。
Query OK, 0 rows affected (0.03 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会飞的爱迪生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值