当前位置:网站首页>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
边栏推荐
- Pd1.4 to hdmi2.0 adapter cable disassembly.
- 黑马畅购商城---2.分布式文件存储FastDFS
- 15. Notes on the button style of WPF
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the summary function to obtain the summary statistical information
- flutter常用命令及问题
- 【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?
- JS monitors the width and height changes of div
- Set the transparency of the picture to gradient from left to right
- 网络 | traceroute,路由跟踪命令,用于确定 IP 数据包访问目标地址所经过的路径。
- JS to realize the calculation of discrete aggregation points
猜你喜欢

Why can't you Ping the website but you can access it?

How far is it from the DBF of VFP to the web salary query system?
![[论]Learning Dynamic and Hierarchical Traffic Spatiotemporal Features with Transformer](/img/58/d68112a3d019de66150e2f5102f436.png)
[论]Learning Dynamic and Hierarchical Traffic Spatiotemporal Features with Transformer

Why can't the form be closed? The magic of revealing VFP object references

Dark horse shopping mall ---6 Brand, specification statistics, condition filtering, paging sorting, highlighting

揭秘GaussDB(for Redis):全面對比Codis

【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?

Black Horse Chang Shopping Mall - - - 3. Gestion des produits de base

Dark horse shopping mall ---3 Commodity management

confluence7.4. X upgrade record
随机推荐
Dark horse shopping mall ---6 Brand, specification statistics, condition filtering, paging sorting, highlighting
Which securities company's account is better and safer to open
一套自动化无纸办公系统(OA+审批流)源码:带数据字典
An easy-to-use seal design tool - (can be converted to ofd file)
What is principal component analysis? Dimension reduction of classical case analysis variables
【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、epiDisplay包的poisgof函数对拟合的泊松回归模型进行拟合优度检验(检验模型效果)
PD1.4转HDMI2.0转接线拆解。
Ten commandments of self-learning in machine learning
Uncover gaussdb (for redis): comprehensive comparison of CODIS
R语言dist函数计算dataframe数据中两两样本之间的距离返回样本间距离矩阵,通过method参数指定距离计算的方法、例如欧几里得距离
[论]Learning Dynamic and Hierarchical Traffic Spatiotemporal Features with Transformer
ARM 立即数
Does sklearex make your sklearn machine learning model training fly fast?
Why can't you Ping the website but you can access it?
Redis雪崩、穿透和击穿是什么?
ROS notes (06) - definition and use of topic messages
15、wpf之button样式小记
Pycaret successfully resolved the problem that 'sklearn model_ selection._ Search 'import name "\u check\u param\u grid"
使用php脚本查看已开启的扩展