Safely remove MySQL binlog logs

Source: Internet
Author: User

For business reasons, you can't keep logs for a fixed number of days, and you can't have the disk space station full, so you can only delete binlog manually.

Using the Purge command that comes with MySQL

PURGE MASTER LOGS to ' mysql-bin.000002 '; Delete the Binlog log before 002 (not including 002),


[[email protected] data]# ls

DBmaster.test.err ib_logfile0 localhost.pid mysql-bin.000002 mysql-bin.000005 performance_schema wine_test

DBmaster.test.pid ib_logfile1 mysql mysql-bin.000003 mysql-bin.000006 test

Ibdata1 localhost.err mysql-bin.000001 mysql-bin.000004 mysql-bin.index WINE_CN




Mysql> PURGE MASTER LOGS to ' mysql-bin.000002 ';


[[email protected] data]# ls

DBmaster.test.err ib_logfile0 localhost.pid mysql-bin.000003 mysql-bin.000006 test

DBmaster.test.pid ib_logfile1 MySQL mysql-bin.000004 mysql-bin.index wine_cn

Ibdata1 localhost.err mysql-bin.000002 mysql-bin.000005 performance_schema wine_test


PURGE MASTER LOGS to ' mysql-bin.000005 ';


[[email protected] data]# ls

DBmaster.test.err ibdata1 ib_logfile1 localhost.pid mysql-bin.000005 mysql-bin.index test wine_test

DBmaster.test.pid ib_logfile0 localhost.err MySQL mysql-bin.000006 performance_schema wine_cn

[Email protected] data]#



#!/bin/bash

# date:2014-06-11

# Database Delete-ge 30day binlog Feil

Cd/dbdata/mysql

#logname = (' Find '/-maxdepth 1-type f-mtime +30-name ' mysql-bin.* ' |sed-n ' 1p;\ $p ' |awk-f '/' {print $} ')

Logname= ' Find/-maxdepth 1-type f-mtime +30-name "mysql-bin.*" |sed-n ' $p ' |awk-f '/' {print $} '

Echo $logname

Mysql-uroot-p123456-e "PURGE MASTER LOGS to ' $logname ';"



mysql> CREATE USER ' binlog ' @ ' localhost ' identified by ' mypass123 ';

Query OK, 0 rows affected (0.05 sec)


Mysql> GRANT SUPER on * * to ' binlog ' @ ' localhost ';

Query OK, 0 rows Affected (0.00 sec)


This article is from the "Small Box" blog, please be sure to keep this source http://zhangxiaohe.blog.51cto.com/7821029/1545478

Safely remove MySQL binlog logs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.