当前位置:网站首页>MySQL日志保留策略:设置binlog日志保存天数、文件大小限制
MySQL日志保留策略:设置binlog日志保存天数、文件大小限制
2022-04-22 22:41:00 【Mr.zhou_Zxy】
MySQL日志保留策略:设置binlog日志保存天数、文件大小限制
一、查看当前binlog保留时长,文件大小限制
## 查看binlog的保留时长[expire_logs_days]
## 0表示永久保留
mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 0 |
+------------------+-------+
1 row in set (0.00 sec)
## 查看binlog的文件大小限制[max_binlog_size]
## 1073741824
mysql> show variables like 'max_binlog_size';
+-----------------+------------+
| Variable_name | Value |
+-----------------+------------+
| max_binlog_size | 1073741824 |
+-----------------+------------+
1 row in set (0.01 sec)
二、修改保留时长
临时生效:
这种方法调整后,立即生效,但是数据库重启后,会失效
## 设置日志保留时长为30天
mysql> set global expire_logs_days=30;
Query OK, 0 rows affected (0.00 sec)
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 30 |
+------------------+-------+
1 row in set (0.00 sec)
mysql>
永久生效:
修改my.cnf文件,永久生效,数据库启动的适合会自动加载该文件
## 打开my.cnf配置文件
[root@zxy_slave1 mysql]# vim /etc/my.cnf
## [mysqld]模块下添加:expire_logs_days
[mysqld]
expire_logs_days = 30
三、设置文件大小限制
临时生效:
这种方法调整后,立即生效,但是数据库重启后,会失效
## 将max_binlog_size设置为500M
mysql> set global max_binlog_size = 524288000;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_binlog_size';
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| max_binlog_size | 524288000 |
+-----------------+-----------+
1 row in set (0.00 sec)
mysql> flush logs;
Query OK, 0 rows affected (0.02 sec)
永久生效
修改my.cnf文件,永久生效,数据库启动的适合会自动加载该文件
## 打开my.cnf配置文件
[root@zxy_slave1 mysql]# vim /etc/my.cnf
## [mysqld]模块下添加:max_binlog_size
[mysqld]
expire_logs_days = 30
max_binlog_size = 500M
四、手动清理binlog
按照binlog名称删除
## 将mysql-bin.000010之前的日志清理掉
mysql> purge binary logs to 'mysql-bin.000010';
Query OK, 0 rows affected (0.01 sec)
## 清理前
[root@zxy_slave1 mysql]# ls
mysql-bin.000007 mysql-bin.000012 mysql-bin.000017 mysql-bin.000008 mysql-bin.000013 mysql-bin.index mysql-bin.000009 mysql-bin.000014 mysql-bin.000005 mysql-bin.000010 mysql-bin.000015 mysql-bin.000006 mysql-bin.000011 mysql-bin.000016
## 清理后
[root@zxy_slave1 mysql]# ls
mysql-bin.000012 mysql-bin.000017 mysql-bin.000013 mysql-bin.index mysql-bin.000014 mysql-bin.000010 mysql-bin.000015 mysql-bin.000011 mysql-bin.000016
[root@zxy_slave1 mysql]#
按照时间删除
## 删除2022-04-21 18:08:00之前的binlog日志
mysql> purge binary logs before '2022-04-21 18:08:00';
Query OK, 0 rows affected, 1 warning (0.02 sec)
## 删除前
[root@zxy_slave1 mysql]# vim mysql-bin.
mysql-bin.000010 mysql-bin.000012 mysql-bin.000014 mysql-bin.000016 mysql-bin.index
mysql-bin.000011 mysql-bin.000013 mysql-bin.000015 mysql-bin.000017
[root@zxy_slave1 mysql]# ls
## 删除后
[root@zxy_slave1 mysql]# ls
mysql-bin.000017 mysql-bin.index
版权声明
本文为[Mr.zhou_Zxy]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_51197424/article/details/124328403
边栏推荐
- 做到与做好,国产引擎 Cocos 如何丛林突围?
- C get the class name or method name of the caller
- ansible yum仓库
- Person re identification: past, present and future
- 数据去重-复杂数据类型
- [MRCTF2020]Ez_ bypass
- [in simple terms and reinforcement learning] 2 Markov decision process
- Basic use and principle of Minio
- js力扣每日一题(2022/4/22)---396.旋转函数
- 抖音商品详情
猜你喜欢

Principle of leftmost matching principle

Kubernetes详解(八)——Kubernetes资源配置清单

C add log4net log (console and file) to console application

How to use opcua protocol on appinventor?

多线程-线程通信(wait-notify,await-single,park-unpark)

Acl2022 | using Chinese language hierarchy heterogeneity map to strengthen the pre training language model

Anti DDoS attack forwarding IP. Is the advanced anti IP of chess and card games easy to use?

最左匹配原则的原理
![[MRCTF2020]Ez_ bypass](/img/11/6278377c6273eca16716bc73c8a63b.png)
[MRCTF2020]Ez_ bypass

多线程进阶(八)----线程池
随机推荐
给复杂的数组结构数据换key
CVPR 2022:微笑识别也带性别歧视?浙大武大联合蚂蚁Adobe搞了个公平性提升框架
[Luogu] p1162 filling color (BFS)
Saiweidian broke on the first day of listing: the market value evaporated by more than 1.5 billion yuan, and the business scale lost slightly
Online yaml to XML tool
L1-066 猫是液体 (5 分)
How to obtain geographical location based on photos and how to prevent photos from leaking geographical location
牛客BM41. 输出二叉树的右视图
The PMP certificate has expired. Is it necessary to renew it
数组排序-基础数据类型排序
[MRCTF2020]Ez_ bypass
并发的可达性分析(三色标记法)
用 Flutter 写一个精美的登录页面(最新版)
续集:几句简单,但很有用的话
等价多米诺骨牌对的数量-c语言实现
Go语言-使用协程高效计算0-2000内每个数的累加
php 一维数组去重
Realizing tab switching with foreach and ES6
安装scVI及使用教程
Basic use and principle of Minio