Linux system to clean MySQL log files mysql-bin.00000

Source: Internet
Author: User

First of all, mysql-bin.00000* similar files are MySQL log files.

by command

The code is as follows Copy Code

Du-h–max-depth=1/

View the storage size of each folder under the root directory, found that/var occupied a fast 3G, further use du command, found that the folder that holds the MySQL data files occupies most of the space, into the folder, Found that there are many mysql-bin.00000 the beginning of the file, and some of them reached more than 1G, Google found that the original users are MySQL records log files, for the database after the crash recovery data and master-slave database data synchronization. If there is no master-slave database, you can modify the configuration file to let MySQL turn off logging operation log function, close only need to add a "#" in front of the log-bin=mysql-bin, do not forget to restart the MySQL service.

The cleanup log method is:

The code is as follows Copy Code

PURGE MASTER LOGS to ' mysql-bin.000013 ';
Or
PURGE MASTER LOGS before ' 2010-10-18 00:00:00 ';

In addition, you can delete the entire log file with RESET Master, and note that if you use the master-slave database, make sure that the primary database is fully synchronized from the database before the operation.
The above commands are logged to MySQL after the implementation.


Many people installed MySQL is opened log file records, generally have more frequent MySQL database operations will produce a large number of log files under/usr/local/mysql/var/, generally generated log files are similar to the following:

-rw-rw--1 mysql mysql 2.0M Sep 17:08 mysql-bin.000001
-rw-rw--1 mysql mysql 1.1G Nov 14:43 mysql-bin.000002
-rw-rw--1 mysql mysql 1.1G Nov 15:17 mysql-bin.000003
-rw-rw--1 mysql mysql 561M Nov 15:52 mysql-bin.000004
-rw-rw--1 mysql mysql 904K Nov 16:07 mysql-bin.000005
-rw-rw--1 mysql mysql 194M Nov 16:40 mysql-bin.000006
-rw-rw--1 mysql mysql 123M Nov 19:18 mysql-bin.000007
-rw-rw--1 mysql MySQL 456 Nov 16:41 mysql-bin.index

From the above, you can see that these mysql-bin.00000* similar files are very large, and generally in dozens of MB to a few GB, more will eat the entire hard disk space, never lead to MySQL can not start or error, so we do not have to open the log file without the necessary circumstances.

First of all, delete the MySQL log method:

Executive:/usr/local/mysql/bin/mysql-u root-p

Enter password to log in and then execute:

The code is as follows Copy Code

Reset Master;

This can be done, of course, can also be manually deleted, but there may be some side effects, I did not confirm.
These files are MySQL log files, used to recover data after a database crash and the master-slave database for data synchronization. If there is no master-slave database, you can modify the configuration file to let MySQL turn off logging operations log function, then how to avoid the future generation of these files, how to turn off the MySQL log function?
The method is as follows:

The code is as follows Copy Code
Vi/etc/my.cnf

Found it:

The code is as follows Copy Code

Log-bin=mysql-bin

Comment out this line, precede with #, and restart MySQL.

If you are manually deleted MySQL log file (mysql-bin.00000*) found that MySQL can not start, So if you look at Mysql-bin.index This file is still there, if it still exists, delete the Mysql-bin.index, and then you can start it normally.

Other cleanup methods (in the case of the login database):

The code is as follows Copy Code

PURGE MASTER LOGS to ' mysql-bin.000013′;
Or
PURGE MASTER LOGS before ' 2010-10-18 00:00:00′;

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.