Mysql's mysql-bin is the operation log file of the database. If master-slave replication is not performed, it is basically useless.
For example, if you UPDATE a table, or DELETE some data, even if the statement does not match the data, this command will be stored in the log file, and the execution time of each statement will also be recorded.
There are two main purposes for doing this:
1: Data recovery If there is a problem with your database and you have had a backup before, you can look at the logs file, find out which command caused the problem in your database, and find a way to recover the loss.
2: Synchronize data between master and slave servers. All operations on the master server are recorded in the log, and the slave server can proceed based on the log to ensure synchronization between the two. For example: When using a single mysql server service, you can comment out the corresponding log-bin=/program/mysql/mysql-bin item, add the "#" sign and restart the mysql service.
How to delete the mysql-bin file?
By default, mysql will always keep the mysql-bin file, so at a certain point, the disk may be full. Although the file is useless, it is not recommended to use the rm command to delete it, which may cause problems. It is not safe. The correct way is to delete it through the mysql command.
mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2819416 Server version: 5.5.24-0ubuntu0.12.04.1-log (Ubuntu) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> reset master; Query OK, 0 rows affected (3 min 37.65 sec)
In fact, the key command is reset master; this command will clear the mysql-bin file.
In addition, if your mysql server does not require master-slave replication, it is recommended to modify the my.cnf file to set these files not to be generated. Just delete the following line in my.cnf.
log-bin=mysql-bin
If you need to copy, it is best to control the number of days that these log files are retained. You can set the number of days that the log files are retained through the following configuration:
expire_logs_days = 7
means Keep logs for 7 days, so old logs will be automatically cleared.
The above is the detailed content of What file is mysql-bin?. For more information, please follow other related articles on the PHP Chinese website!