zoukankan      html  css  js  c++  java
  • 自动清理MySQL binlog日志

    开启MySQL binlog日志的服务器,如果不设置自动清理日志,默认binlog日志一直保留着,时间一长,服务器磁盘空间被binlog日志占满,导致MySQL数据库出错。

    使用下面方法可以安全清理binlog日志

    一、没有主从同步的情况下清理日志

    mysql -uroot -p123456 -e 'PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ),INTERVAL 5 DAY)';

    #mysql 定时清理5天前的binlog

    mysql -u root -p  #进入mysql 控制台

    reset master;  #重置binlog

    二、MySQL主从同步下安全清理binlog日志

    1、mysql  -u root -p   #进入从服务器mysql控制台

    show slave statusG;   #检查从服务器正在读取哪个日志,有多个从服务器,选择时间最早的一个做为目标日志。

    2、进入主服务器mysql控制台

    show master log;   #获得主服务器上的一系列日志

    PURGE MASTER LOGS TO 'binlog.000058';   #删除binlog.000005之前的,不包括binlog.000058

    PURGE MASTER LOGS BEFORE '2016-06-22 13:00:00';  #清除2016-06-22 13:00:00前binlog日志

    PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);  #清除3天前binlog日志

    三、设置自动清理MySQL binlog日志

    vi  /etc/my.cnf  #编辑配置

    expire_logs_days = 15  #自动删除15天前的日志。默认值为0,表示从不删除。

    log-bin=mysql-bin   #注释掉之后,会关闭binlog日志

    binlog_format=mixed   #注释掉之后,会关闭binlog日志

    :wq!  #保存退出

    扩展阅读:

    mysql> help purge;

    Name: 'PURGE BINARY LOGS'

    Description:

    Syntax:

    PURGE { BINARY | MASTER } LOGS

    { TO 'log_name' | BEFORE datetime_expr }

    The binary log is a set of files that contain information about data

    modifications made by the MySQL server. The log consists of a set of

    binary log files, plus an index file (see

    http://dev.mysql.com/doc/refman/5.5/en/binary-log.html).

    The PURGE BINARY LOGS statement deletes all the binary log files listed

    in the log index file prior to the specified log file name or date.

    BINARY and MASTER are synonyms. Deleted log files also are removed from

    the list recorded in the index file, so that the given log file becomes

    the first in the list.

    This statement has no effect if the server was not started with the

    --log-bin option to enable binary logging.

    URL: http://dev.mysql.com/doc/refman/5.5/en/purge-binary-logs.html

    Examples:

    PURGE BINARY LOGS TO 'mysql-bin.010';

    PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

  • 相关阅读:
    make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
    安卓端与开发板通信
    openwrt串口的使用
    .OpenWrt驱动程序Makefile的分析概述 、驱动程序代码参考、以及测试程序代码参考
    openwrt系统之字符设备驱动软件包加载、测试程序加载
    cc2530串口通信流程
    cc2530操作任务系统初始化分析
    总结OpenWrt系统基本操作方法
    Zigbee协议栈OSAL层API函数【转载】
    cc2530启动流程---广播发送数据
  • 原文地址:https://www.cnblogs.com/cheyunhua/p/8459200.html
Copyright © 2011-2022 走看看