Mysql 8.0 关闭binlog日志

Mysql8.0默认开启binlog记录功能,导致磁盘空间占用很大,8.0关闭的方式跟之前5.x的不太一样。

1.清除binlog文件

$ mysql -u root -p
#进入数据库查看log_bin状态
mysql> show variables like ‘log_bin';
+—————+——-+
| Variable_name | Value |
+—————+——-+
| log_bin | ON |
+—————+——-+
1 row in set (0.01 sec)

#查看现有在用的binlog日志
mysql> show master logs;
+—————+————+———–+
| Log_name | File_size | Encrypted |
+—————+————+———–+
| binlog.000020 | 1073742151 | No |
| binlog.000021 | 1073747018 | No |
| binlog.000022 | 1073930151 | No |
| binlog.000023 | 1073733807 | No |
+—————+————+———–+
4 rows in set (0.03 sec)

#手动清除binlog日志
mysql> reset master;
Query OK, 0 rows affected (0.02 sec)

#退出mysql
mysql> \q

2.关闭

#编辑配置文件/etc/my.cnf,添加disable_log_bin,有些版本可能是:skip-log-bin
$ vim /etc/my.cnf
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading “# ” to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It’s default setting is log_bin=binlog
disable_log_bin
#skip-log-bin

#重启mysql服务
$ service mysqld restart

$ mysql -u root -p
#再次进入数据库查看log_bin状态
mysql> show variables like ‘log_bin';
+—————+——-+
| Variable_name | Value |
+—————+——-+
| log_bin | OFF |
+—————+——-+
1 row in set (0.01 sec)

#查看binlog日志报错提醒没有开启binlog
mysql> show master logs;
ERROR 1381 (HY000): You are not using binary logging

3.清理binlog

除了使用reset master清理日志文件之外,还可以按照日期清理:

purge master logs before ‘2024-01-18 00:00:00′;

Leave a Comment

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |