当前位置:网站首页>Mysql database logs binlog save aging (expire\u logs\u days)
Mysql database logs binlog save aging (expire\u logs\u days)
2022-06-25 12:23:00 【lihongbao80】
One 、 Set Syntax
1、 Method 1 :
edit /etc/my.cnf file , stay [mysqld] Add the following two lines to the node
max_binlog_size = 500M
expire_logs_days = 15
max_binlog_size:bin log Every time the log reaches the set size , Will use the new bin log journal . Such as mysql-bin.000002 achieve 500M after , Create and use mysql-bin.000003 File as logging .
expire_logs_days: Keep... Within the specified date range bin log Historical Journal , The 15 Days. .
2、 Method 2 :
-- mysql8.0 The following versions view the current database logs binlog Time limit of preservation In days , Default 0 Never expire , You can only set at most 99 God
show variables like 'expire_logs_days';
set global expire_logs_days=60;
-- mysql8.0 The above versions set global parameters binlog_expire_logs_seconds modify binlog Storage time In seconds ; Default 2592000 30 God 14400 4 Hours ;86400 1 God ;259200 3 God
show variables like '%binlog_expire_logs_seconds%';
set global binlog_expire_logs_seconds=259200;
Two 、 Expiration deletion policy
summary :
Through the following experiments , about mysql binlog Expiration deletion policy , We can speculate as follows .
1. mysql It's based on binlog The last time the operating system of the file was modified , To judge binlog Is it overdue ( Not based on binlog The time of occurrence in the log ).
2. It's triggering mysql On expiration deletion ,mysql First check *bin.index file , Find the oldest binlog, Then check the system time of the file , There are two situations :
1) If you find that the file is not expired , They think that there is no binlog Log expiration , Do not delete , Even if there are other binlog Has expired .
2) If the file is found to be out of date , Will find the next binlog, Judge whether it is overdue , There are also two cases ( Expired or not expired ), So back and forth , Until you find the first expired binlog That is, stop searching , And delete the binlog And all that binlog All previous logs
1. view the database binlog list
1)
mysql> show binary logs;
+-----------------+------------+
| Log_name | File_size |
+-----------------+------------+
| 3306-bin.000006 | 1074742033 |
| 3306-bin.000007 | 1074580678 |
| 3306-bin.000008 | 1074739627 |
| 3306-bin.000009 | 250635228 |
| 3306-bin.000010 | 120 |
+-----------------+------------+
5 rows in set (0.00 sec)
2)
ls -lrt
total 7402312
-rw-r--r-- 1 root root 1747 Mar 25 10:06 test
-rw-rw---- 1 mysql mysql 1074742032 May 4 16:48 3306-bin.000006
-rw-rw---- 1 mysql mysql 1074580678 May 4 16:54 3306-bin.000007
-rw-rw---- 1 mysql mysql 1074739627 May 4 17:00 3306-bin.000008
-rw-rw---- 1 mysql mysql 168 May 4 17:00 3306-bin.index
-rw-rw---- 1 mysql mysql 250635182 May 4 17:02 3306-bin.000009
-rw-rw---- 1 mysql mysql 10448198 May 27 05:04 slow3306.log
-rw-r----- 1 mysql root 1096759 May 27 05:06 error3306.log
-rw-rw---- 1 mysql mysql 4093675902 May 27 05:06 general3306.log
## We see mysql For the time being 4 individual binlog journal , The serial number from 6 To 9, The serial number currently in use is 9 Log
2. Set up binlog Expiration time
set global expire_logs_days=7;
## In the 1 In this step we can see 3306-bin.000006,3306-bin.000007,3306-bin.000008 All three logs are expired ( because 3306-bin.000009 Is the log currently in use , So it is not an expired log )
3. modify 3306-bin.000006 File system time
Use vi see 3306-bin.000006 file , Save and exit without any changes .
4. Check after modification binlog File time
ls -lrt
total 7402312
-rw-r--r-- 1 root root 1747 Mar 25 10:06 test
-rw-rw---- 1 mysql mysql 1074580678 May 4 16:54 3306-bin.000007
-rw-rw---- 1 mysql mysql 1074739627 May 4 17:00 3306-bin.000008
-rw-rw---- 1 mysql mysql 168 May 4 17:00 3306-bin.index
-rw-rw---- 1 mysql mysql 250635182 May 4 17:02 3306-bin.000009
-rw-rw---- 1 mysql mysql 10448198 May 27 05:04 slow3306.log
-rw-r----- 1 mysql root 1096759 May 27 05:06 error3306.log
-rw-rw---- 1 mysql mysql 4093675902 May 27 05:06 general3306.log
-rw-rw---- 1 mysql mysql 1074742033 May 27 10:13 3306-bin.000006
##3306-bin.000006 The log file has been changed. The system log has become the time of the day
5. flush logs
## We know flush logs; Will trigger the expired log cleanup operation
6. View existing binlog
1)
mysql> show binary logs;
+-----------------+------------+
| Log_name | File_size |
+-----------------+------------+
| 3306-bin.000006 | 1074742033 |
| 3306-bin.000007 | 1074580678 |
| 3306-bin.000008 | 1074739627 |
| 3306-bin.000009 | 250635228 |
| 3306-bin.000010 | 120 |
+-----------------+------------+
5 rows in set (0.00 sec)
2)
ls -lrt
total 7402316
-rw-r--r-- 1 root root 1747 Mar 25 10:06 test
-rw-rw---- 1 mysql mysql 1074580678 May 4 16:54 3306-bin.000007
-rw-rw---- 1 mysql mysql 1074739627 May 4 17:00 3306-bin.000008
-rw-r----- 1 mysql root 1096759 May 27 05:06 error3306.log
-rw-rw---- 1 mysql mysql 1074742033 May 27 10:13 3306-bin.000006
-rw-rw---- 1 mysql mysql 10448370 May 27 10:14 slow3306.log
-rw-rw---- 1 mysql mysql 4093676334 May 27 10:14 general3306.log
-rw-rw---- 1 mysql mysql 250635228 May 27 10:14 3306-bin.000009
-rw-rw---- 1 mysql mysql 120 May 27 10:14 3306-bin.000010
-rw-rw---- 1 mysql mysql 210 May 27 10:14 3306-bin.index
## We found that 3306-bin.000006,3306-bin.000007,3306-bin.000008 Three logs have not been deleted ( here 3306-bin.000006 The file system time is the same day ,3306-bin.000007 and 3306-bin.000008 The file time is 4 Number )
7. purge One of the earliest 3306-bin.000006 journal
1)
mysql> purge master logs to '3306-bin.000007';
Query OK, 0 rows affected (0.31 sec)
2)
mysql> show binary logs;
+-----------------+------------+
| Log_name | File_size |
+-----------------+------------+
| 3306-bin.000007 | 1074580678 |
| 3306-bin.000008 | 1074739627 |
| 3306-bin.000009 | 250635228 |
| 3306-bin.000010 | 120 |
+-----------------+------------+
4 rows in set (0.01 sec)
3)
ls -lrt
total 6352756
-rw-r--r-- 1 root root 1747 Mar 25 10:06 test
-rw-rw---- 1 mysql mysql 1074580678 May 4 16:54 3306-bin.000007
-rw-rw---- 1 mysql mysql 1074739627 May 4 17:00 3306-bin.000008
-rw-r----- 1 mysql root 1096759 May 27 05:06 error3306.log
-rw-rw---- 1 mysql mysql 10448370 May 27 10:14 slow3306.log
-rw-rw---- 1 mysql mysql 250635228 May 27 10:14 3306-bin.000009
-rw-rw---- 1 mysql mysql 120 May 27 10:14 3306-bin.000010
-rw-rw---- 1 mysql mysql 168 May 27 10:17 3306-bin.index
-rw-rw---- 1 mysql mysql 4093676603 May 27 10:17 general3306.log
##3306-bin.000006 The log has been deleted
8. Again flush logs;
1) flush logs;
mysql> flush logs;
Query OK, 0 rows affected (0.30 sec)
2) see binlog
mysql> show binary logs;
+-----------------+-----------+
| Log_name | File_size |
+-----------------+-----------+
| 3306-bin.000009 | 250635228 |
| 3306-bin.000010 | 166 |
| 3306-bin.000011 | 120 |
+-----------------+-----------+
3 rows in set (0.00 sec)
ls -lrt
total 4253804
-rw-r--r-- 1 root root 1747 Mar 25 10:06 test
-rw-r----- 1 mysql root 1096759 May 27 05:06 error3306.log
-rw-rw---- 1 mysql mysql 250635228 May 27 10:14 3306-bin.000009
-rw-rw---- 1 mysql mysql 10448542 May 27 10:17 slow3306.log
-rw-rw---- 1 mysql mysql 4093676814 May 27 10:17 general3306.log
-rw-rw---- 1 mysql mysql 166 May 27 10:17 3306-bin.000010
-rw-rw---- 1 mysql mysql 120 May 27 10:17 3306-bin.000011
-rw-rw---- 1 mysql mysql 126 May 27 10:17 3306-bin.index
## At this time, we found that 3306-bin.000007,3306-bin.000008 The log has been automatically deleted
边栏推荐
- 什么是Flink?Flink能用来做什么?
- Time series analysis - how to use unit root test (ADF) correctly?
- How to use SPSS to do grey correlation analysis? Quick grasp of hand-to-hand Teaching
- Pd1.4 to hdmi2.0 adapter cable disassembly.
- R语言dplyr包filter函数过滤dataframe数据中指定数据列的内容不是(不等于指定向量中的其中一个)指定列表中的数据行
- confluence7.4.X升级实录
- Arm V7 LDR STR memory access
- 15. Notes on the button style of WPF
- Old ou, a fox friend, has had a headache all day. The VFP format is always wrong when it is converted to JSON format. It is actually caused by disordered code
- What is principal component analysis? Dimension reduction of classical case analysis variables
猜你喜欢

Architects reveal the difference between working in Alibaba, Tencent and meituan

What is Flink? What can Flink do?

Old ou, a fox friend, has had a headache all day. The VFP format is always wrong when it is converted to JSON format. It is actually caused by disordered code

Database Series: MySQL index optimization summary (comprehensive version)

使用php脚本查看已开启的扩展

Actual combat summary of Youpin e-commerce 3.0 micro Service Mall project

What is principal component analysis? Dimension reduction of classical case analysis variables
![[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?](/img/51/9aceaaeed1f6db7c60685d53477eba.png)
[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?

ROS notes (06) - definition and use of topic messages

Rank sum ratio comprehensive evaluation method for common models in mathematical modeling
随机推荐
R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
Kotlin学习笔记
Use PHP script to view the opened extensions
If you also want to be we media, you might as well listen to Da Zhou's advice
Continue to cut the picture after the ArcGIS Server is disconnected
[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?
The network traceroute command is used to determine the path through which IP packets access the destination address.
Why should Apple change objc_ Type declaration for msgsend
WebRTC Native M96 基础Base模块介绍之网络相关的封装
Explain factor analysis in simple terms, with case teaching (full)
How far is it from the DBF of VFP to the web salary query system?
An easy-to-use seal design tool - (can be converted to ofd file)
ROS notes (06) - definition and use of topic messages
apple 为什么要改 objc_msgSend 的类型申明
Cesium editing faces
2020最新最全IT学习线路
Mpai data science platform random forest classification \ explanation of regression parameter adjustment
R language uses GLM function to build Poisson logarithmic linear regression model, processes three-dimensional contingency table data to build saturation model, and poisgof function of epidisplay pack
ROS 笔记(06)— 话题消息的定义和使用
15、wpf之button样式小记