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.
======================================
Before the discovery of their own 10G server space size, with a few days left 5 G, the files uploaded by themselves only hundreds of M, in the end what is occupied by such a large space? There is time to thoroughly check it out today:
Look at the above directory Web root is placed in home/home, all files add up to less than 300M, and the server has taken up nearly 5G space, horror bar, and finally through my step by step query to know that the original is this folder accounted for a lot of space resources:
So that is the MySQL folder under the Var directory occupies the most space, what is it? Let's see:
Found so many mysql-bin.0000x files, what is this? This is the MySQL operation log file. I am only dozens of m database, operation log incredibly fast 3G size.
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 above posts to go from the long Cool blog
The source and processing method of mysql-bin.000001 file