The source and processing method of mysql-bin.000001 file

Source: Internet
Author: User

After installing MySQL with ports, after a period of time found that the/var space is insufficient, check, you will find that mysql-bin.000001, mysql-bin.000002 and other documents occupy space, then what are these files? This is the operation log of the database, such as update a table, or delete some data, even if the statement does not have matching data, this command will be stored in the log file, also includes the time of each statement execution, also recorded in.

This has the following two purposes:
1: Data recovery
If your database is out of order and you have a previous backup, you can look at the log file to find out which command caused your database to go wrong and try to recover the loss.
2: Synchronizing data between master and slave servers
All operations on the primary server are recorded in the log, which can be performed from the server to ensure two synchronizations.

There are two kinds of processing methods:
1: Only one MySQL server, then you can simply comment out this option is OK.
Vi/etc/my.cnf the inside of the Log-bin this line commented out, restart the MySQL service.
2: If your environment is a master-slave server, then you need to do the following.
A: On each subordinate server, use Show SLAVE status to check which log it is reading.
B: Use show master logs to get a series of logs on the primary server.
C: In all subordinate servers to determine the oldest log, this is the target log, if all the subordinate server is updated, is the last log on the list.
D: Clean up all the logs, but not the target log, since the server also synchronizes with it.
The cleanup log method is:
PURGE MASTER LOGS to ' mysql-bin.010 ';
PURGE MASTER LOGS before ' 2008-12-19 21:00:00 ';
If you are sure that the server has been synchronized with the primary server, then you can delete the files directly from reset Master.

How do I delete a mysql-bin.0000x log file?

Red indicates the input command.

[Email protected] var]# /usr/local/mysql/bin/mysql-u root-p
Enter Password: ( enter password)
Welcome to the MySQL Monitor. Commands End With; Or/g.
Your MySQL Connection ID is 264001
Server Version:5.1.35-log Source Distribution

Type ' help; ' or '/h ' for help. Type '/C ' to clear the current input statement.

mysql> Reset Master; (Clear log file)
Query OK, 0 rows affected (8.51 sec)

Mysql>

OK, let's see how much space is in the MySQL folder?

[Email protected] var]# du-h–max-depth=1/usr/local/mysql/
37m/usr/local/mysql/var
70m/usr/local/mysql/mysql-test
15m/usr/local/mysql/lib
448k/usr/local/mysql/include
2.9m/usr/local/mysql/share
7.6m/usr/local/mysql/libexec
17m/usr/local/mysql/bin
11m/usr/local/mysql/docs
2.9m/usr/local/mysql/sql-bench
163m/usr/local/mysql/

OK, look, the entire MySQL directory takes up 163M size! OK, no problem, since the mysql-bin.0000x log file occupies such a large space, the significance of the existence is not particularly large, then we will not let it generate it.

[Email protected] var]# Find/-name my.cnf

Find the MY.CNF is the MySQL configuration file, we will log-bin=mysql-bin this comment out.

# Replication Master Server (default)
# Binary logging is required for replication
#log-bin=mysql-bin

Restart the MySQL bar.

OK, at this point, the operation is complete. You will never generate N-G log files for a database size of dozens of M.

These log files are too scary, I moved to this new VPS to only 20 days or so, less than one months log file incredibly close to 3 G size, if a month or two I do not clear the log file this also got!

The source and processing method of mysql-bin.000001 file

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.