mysql method to clear the ES1en ES2en log

  • 2020-06-19 11:49:41
  • OfStack

I have been busy with my work projects for the past 1 year. Recently, I will carry out a department adjustment and do a new project. It's exciting to learn so much more. Today, I came back from work to check the status of VPS and found that there was only more than 1G left in VPS! The first reaction was that it was hacked, but after looking at log for 1 time, no abnormal login was found. In addition, VPS, which usually logs in with private key and password free, may not be a big one. Then I am very confused, because the system file should take up only 3G, I usually did not miss any large file in VPS, should not be 1 so much space. So began 1 du search finally found the culprit! It turned out to be the log file for mysql.

After installing mysql and running for a period of time, a heap similar to ES15en-ES16en.000 *** appeared in mysql directory, which was arranged from ES17en-ES18en.000001 straight down and took up a lot of hard disk space, up to more than 10 G. mysql-bin.000001, ES22en-ES23en.000002 and other files are the operation log of the database, such as UPDATE1 table, or some data of DELETE1. Even if the statement does not have matching data, this command will be stored in the log file, and the execution time of each statement will also be recorded. What are these files in the form of ES26en-ES27en.00001 mainly used for?

1. Data recovery
If you have a database problem and you have a backup, look at the log files, find out which command caused the database problem and find a way to recover the damage.

2. Synchronize data between master and slave servers
All operations on the primary server are logged and can be performed by the slave server to ensure that the two are synchronized.

3. Cleaning method
Run/usr local/mysql/bin/mysql - u root - p logins for:

reset master;

If you only have 1 mysql server, find the my.cnf file vim /etc/ my.cnf file under /etc/
#log-bin=mysql-bin 
#binlog_format=mixed

Comment out these two lines, then delete all these log files from the var directory under mysql, and restart the mysql service.
But if you set up a master-slave server, you need to do the following.
A: On each slave, use SHOW SLAVE STATUS to check which log it is reading.
B: Use SHOW MASTER LOGS to get series 1 logs on the primary server.
C: Determine the earliest log among all slave servers, this is the target log, and the last log on the list if all slave servers are updated.
D: Clean up all the logs, but not the target log, because the slave server also synchronizes with it. Simply put, these MySQL directories contain files such as ES78en-ES79en. 000*** when MySQL's transaction log. It is safe to remove binlog that the replication server has taken away, and generally keep the latest one when the network is in good condition.


Related articles: