mysql主库中设置了打开binlog模式后,会在datadir目录下生成大量的日志文件,mysql默认是不会自动清理的,我们来设置下mysql自动清理binlog文件

一、打开mysql

[root@push-- ~]# mysql -uroot  -p -S /var/lib/mysql//mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7.-log MySQL Community Server (GPL) Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

二、 显示binlog文件

mysql> show binary logs;
| master-221.000689 |  |
| master-221.000690 | |
| master-221.000691 | |
| master-221.000692 | |
| master-221.000693 | |
| master-221.000694 | |
| master-221.000695 | |
| master-221.000696 | |
| master-221.000697 | |
| master-221.000698 | |
| master-221.000699 | |
| master-221.000700 | |
| master-221.000701 | |
| master-221.000702 | |
| master-221.000703 | |
| master-221.000704 | |
| master-221.000705 | |
| master-221.000706 | |
| master-221.000707 | |
| master-221.000708 | |
| master-221.000709 | |
| master-221.000710 | |
| master-221.000711 | |
| master-221.000712 | |
| master-221.000713 | |
| master-221.000714 | |
| master-221.000715 | |
| master-221.000716 | |
| master-221.000717 | |
| master-221.000718 | |
| master-221.000719 | |
| master-221.000720 | |
| master-221.000721 | |
| master-221.000722 | |
| master-221.000723 | |
| master-221.000724 | |
| master-221.000725 | |
| master-221.000726 | |
| master-221.000727 | |
| master-221.000728 | |
| master-221.000729 | |
| master-221.000730 | |
| master-221.000731 | |
+-------------------+------------+
rows in set (0.00 sec)

显示大量的日志文件

通过设置expire_logs_days参数来实现自动删除binlog文件

mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | |
+------------------+-------+
row in set (0.00 sec) mysql>

该参数表示binlog日志自动删除/过期的天数,默认值为0,表示不自动删除

设置为10天过期

mysql> set global expire_logs_days=;
Query OK, rows affected (0.00 sec) mysql> show variables like 'expire_logs_days';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | |
+------------------+-------+
row in set (0.00 sec) mysql>

Mysql设置主库binlog文件自动清理的更多相关文章

  1. 查看MySQL日志数据binlog文件

    binlog介绍 binlog,即二进制日志,它记录了数据库上的所有改变. 改变数据库的SQL语句执行结束时,将在binlog的末尾写入一条记录,同时通知语句解析器,语句执行完毕. binlog格式 ...

  2. centos设置定时删除文件定时清理网站日志

    1.进入linux系统 2.在任意目录创建一个sh后缀的文件,如: 3.编辑打开该文件,如图: 4.此时按键盘上的“i”键或者“insert”键,进入编辑模式 输入: #!/bin/shfind /d ...

  3. 必须了解的mysql三大日志-binlog、redo log和undo log

    日志是 mysql 数据库的重要组成部分,记录着数据库运行期间各种状态信息.mysql日志主要包括错误日志.查询日志.慢查询日志.事务日志.二进制日志几大类.作为开发,我们重点需要关注的是二进制日志( ...

  4. 【原创】数据库基础之Mysql(3)mysql删除历史binlog

    mysql开启binlog后会在/var/lib/mysql下创建binlog文件,如果手工删除,则下次mysql启动会报错: mysqld: File './master-bin.000001' n ...

  5. 自动清理MySQL binlog日志

    开启MySQL binlog日志的服务器,如果不设置自动清理日志,默认binlog日志一直保留着,时间一长,服务器磁盘空间被binlog日志占满,导致MySQL数据库出错. 使用下面方法可以安全清理b ...

  6. MySQL binlog 自动清理脚本

    # vim /data/scripts/delete_mysql_binlog.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  7. 【转载】mysql binlog日志自动清理及手动删除

    说明:当开启mysql数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间.mysql-bin.000001mysql-bin.000002mysql-b ...

  8. mysql binlog日志自动清理及手动删除

    说明:当开启mysql数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间.mysql-bin.000001mysql-bin.000002mysql-b ...

  9. 小记---------maxwell 一个可以实时读取mysql二进制日志binlog,并生成JSON格式的消息,作为生产者发送给kafka,Redis,文件或其他平台的应用程序

    maxwell主要提供了下列功能     支持 SELECT * FROM table 的方式进行全量数据初始化     支持在主库发生failover后,自动回复binlog位置(GTID)     ...

随机推荐

  1. JavaScript(7)——DOM

    什么是 DOM? DOM是 Document Object Model(文档对象模型)的缩写 DOM是 W3C(万维网联盟)的标准. DOM 定义了访问 HTML 和 XML 文档的标准: “W3C ...

  2. linux 自定义函数

    用别人的车子出行,总感觉别扭,那怎么自定义自己的车轮子呢? 通过上面的求两个参数的和例子,我们可以学到定义一个函数基本的步骤, function getSum(){  SUM=$[$n1+$n2]  ...

  3. 《机器学习实战(基于scikit-learn和TensorFlow)》第七章内容学习心得

    本章主要讲述了“集成学习”和“随机森林”两个方面. 重点关注:bagging/pasting.boosting.stacking三个方法. 首先,提出一个思想,如果想提升预测的准确率,一个很好的方法就 ...

  4. Laravel从模型中图片的相对路径获取绝对路径

    在模型product.php中增加以下方法.数据库图片字段为image.存储的图片相对路径 public function getImageUrlAttribute() { // 如果 image 字 ...

  5. Prefix to Infix Conversion

    Infix : An expression is called the Infix expression if the operator appears in between the operands ...

  6. firewall-cmd 的简单使用 进行端口转发的使用

    今天本来想用 ssh 做端口转发 但是命令死活想不起来了.. 没办法改用firewall-cmd 来进行处理 方法: 1. 首先不能关防火墙 systemctl enable firewalld sy ...

  7. MQTT安全篇

    物联网的核心是连接万物,通过交换并分析数据使得生活更舒适与便捷.不过,敏感数据泄露或者设备被非法控制可不是闹着玩的.比如前段时间国内某著名家电企业的智能洗衣机,使用了某著名电商基于XMPP协议的物联网 ...

  8. centos编译安装python3怎么做?

    照着我的博客操作 你一定能成功的!因为我就是一步一步的做出来的,虽然只有文档,但是希望你能有耐心!!!! 编译安装难么麻烦,为什么还要编译安装? 那我告诉你想进步就要折腾!你习惯了windows的安装 ...

  9. centos 秘钥登录

    客户端系统:macOS 服务端系统:Centos7 另外:ip 为 172.25.11.182 用户名为 iamfine 1, 在客户端macOS上生成 rsa 对 ssh-keygen -t rsa ...

  10. 第2章:Python生态工具

    1.Python内置小工具 1).1秒钟启动一个下载服务器: python -m SimpleHTTPServer python3 -m http.server 会在当前目录下启动一个文件下载服务器, ...