What file is mysql bin. 000001 in mysql? Can I delete it

  • 2021-12-04 11:35:20
  • OfStack

After installing mysql with ports, it is found that/var space is insufficient after a period of time. If you check 1, you will find that files such as mysql-bin. 000001 and mysql-bin. 000002 occupy space, so what are these files for? This is the operation log of the database, such as UPDATE1 tables or DELETE1 data. Even if there is no matching data for this statement, this command will be stored in the log file, including the execution time of each statement, which will also be recorded.

This has the following two main purposes:

1: Data recovery
If there is something wrong with your database and you have had a backup before, you can look at the log file to find out which command caused your database to go wrong and find a way to recover the loss.
2: Synchronize data between master and slave servers
All operations on the master server are in the log, and the slave server can proceed according to this log to ensure synchronization between the two.

There are two ways to deal with it:
1: There is only one mysql server, so you can simply comment out this option.
vi/etc/my. cnf comment out the line log-bin and restart the mysql service.
2: If your environment is a master-slave server, you need to do the following.
A: On each slave server, use SHOW SLAVE STATUS to check which log it is reading.
B: Use SHOW MASTER LOGS to obtain Series 1 logs on the primary server.
C: Determine the earliest log among all the slave servers, this is the target log, and if all the slave servers are updated, it is the last log on the list.
D: Clean up all logs, but exclude the target log, because the slave server has to synchronize with it.

The log cleaning 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 slave server has already synchronized, just like the master server 1, you can delete these files directly by RESET MASTER.

Before, I found that the server space of 10G was only 5G after a few days, and the files I uploaded were only a few hundred M. What took up such a large space?

Directory web Root Directory is placed in/home, all the files add up to less than 300M, and the server has occupied nearly 5G space, horror bar, finally through my 1 step 1 query, it turns out that this folder occupies a lot of space resources

So, it is the var directory under the mysql folder that occupies the largest space. What is the content inside? Let's take a look at:

Found so many mysql-bin. 0000X files, what is this? Originally this is mysql operation log file. I just a few 10M database, operation log is fast 3G size.

How do I delete the mysql-bin. 0000X log file?

Red indicates the command entered.

[root@jiucool 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 Files)
Query OK, 0 rows affected (8.51 sec)

mysql >

Ok, let's check how much space the mysql folder takes up.

[root @ jiucool 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 at 1, and the whole mysql directory takes up the size of 163M! OK, no problem. Since the mysql-bin. 0000X log file takes up so much space and is not of great significance, let's not let it be generated.

[root@jiucool var]# find / -name my.cnf

Having found the my. cnf or mysql configuration file, we can comment out log-bin=mysql-bin.

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

Restart mysql.

OK, at this point, the operation is completed. In the future, N G log files will not be generated because of the database size of several 10M.

These log files are too horrible, I moved to this new VPS only about 210 days, less than a month log file actually near 3 G size, if 1 or 2 months I do not clear the log file this also got!

MySql data Directory mysql-bin.000001 File Cleaning Method

Write in MYSQL installation directory, data directory stores all database files, in this directory there are some mysql-bin. 000001, mysql-bin. 000002, mysql-bin. 000003 similar files occupy a lot of space, these files are database operation log files, can be erased. Cleaning method:
Under cmd, enter bin directory under mysql, and enter mysql-u root-p; Then enter the password, and enter reset master after successfully entering.
mysql > reset master;
Query OK, 0 rows affected, 1 warning (0.20 sec)
This deletes the log files. If you don't want to generate these log files, you can do this:
Open my. ini in the mysql directory, find log-bin=mysql-bin and comment it out.
#log-bin=mysql-bin
(It is a good idea to temporarily shut down the MYSQL database while modifying the database configuration file.)


Related articles: