Mysql clears the Log-bin log method _mysql

Source: Internet
Author: User
Tags mysql in vps

Things have been busy for a while, and recently a department change is going to be done for new projects. It's exciting to learn a lot of new knowledge. Today after work back to check the VPS status, found that the VPS space only 1G more! The first reaction was invaded, but looked at the log and did not find anything unusual login, plus usually the basic private key is password-free login vps, do not invade may not be very large. Then I am very puzzled, because the system file consumption should also be more than 3G, I usually do not miss what large files in the VPS, should not be a little less so much space. So began a du search finally found the culprit! The original is the MySQL log file caused.

Install MySQL and run for a period of time, in the MySQL directory appears a bunch of similar mysql-bin.000***, from the beginning of the mysql-bin.000001 has been ranked down, and occupy a lot of hard disk space, up to more than 10 g. Originally mysql-bin.000001, Files such as mysql-bin.000002 are database operations logs, such as update a table, or delete some data, even if the statement does not have matching data, this command will also be stored in the log file, including the time of each statement execution, will also be recorded. What are these mysql-bin.00001 documents mainly for?

1. Data recovery
If you have a database problem, and you have a backup before, then you can look at the log file, find out which command caused your database problem, find a way to recover the loss.

2. Synchronizing data between master and slave servers
all operations on the primary server are in the logging log, which can be done from the server to ensure two synchronizations.

3. Methods of removal
run/usr/local/mysql/bin/mysql-u root-p logon execution:

Copy Code code as follows:
Reset Master;

If you have only one MySQL server, locate the my.cnf file under/etc/vim/etc/my.cnf
Copy Code code as follows:
#log-bin=mysql-bin
#binlog_format =mixed

The two lines are commented out, and then the MySQL in the Var directory under the log files all deleted, restart the MySQL service can be.
But if you set up a master-slave server, then you need to do the following operations.
A: On each subordinate server, use Show SLAVE status to check which log it is reading.
B: Use show master logs to obtain a series of logs on the primary server.
C: In all subordinate servers to determine the earliest 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 because it is also synchronized from the server. Simply put, these MySQL directories are under the shape of a mysql-bin.000*** file when MySQL's transaction log. Delete Replication server has been taken away from the Binlog is safe, in general, when the network condition is good, keep the latest one enough.

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.