Simple collation of Mysql log Operation command _mysql

Source: Internet
Author: User
Tags log log

1. First confirm that your log is enabled

Mysql>show variables like ' log_bin '; 

If enabled, that is, the log file is in the MySQL installation directory in the data directory

2. How to know the current log

Mysql> Show master status; 

3. See binary log file with Mysqlbinlog

Shell>mysqlbinlog mail-bin.000001 

Or

Shell>mysqlbinlog mail-bin.000001 | Tail 

4. Correct removal of MySQL Bin-log log practice

In MySQL will be a large number of such as mysq-bin.000001 such log files, these are binary files, if we are ordinary log without master-slave configuration can be directly used reset Master to delete this method is very simple,
If there is no master-slave replication, you can reset the database log by resetting master, clearing the previous log file:

mysql> Reset Master;


There is also a my.cnf in the configuration.

Expire_logs_days = 3

The number of days that the binary log is automatically deleted. This set the automatic purge 3 days ago of the logs.

The default value is 0, which means "no automatic deletion".


Cases

# by file: Delete mysql-bin.000354 before the log, does not contain mysql-bin.000354

mysql>purge binary logs to ' mysql-bin.000354 ';

Query OK, 0 rows affected (0.16 sec)

# by Time: Delete logs before 00:00:00

mysql>purge binary logs before ' 2011-11- Ten 00:00:00 ';

# by Time: Please three days before the log

mysql> purge master logs before date_sub (now (), Interval 3 day);

Automatic cleanup log:

# Modify MY.CNF file configuration Bin-log expiration


expire-logs-days=7

max-binlog-size=268435456


If you are the master and slave MySQL log file please refer to the following method

Before deleting the log, check the log files currently used by the master/slave server,


///first log on to the server that you want to delete log MySQL terminal
#mysql-u root-pxxxxx


//Check replication master server status
mysql> Show Master Status


+------------------+-----------+--------------+----------------------------------------+
| File       | Position | binlog_do_db | binlog_ignore_db            |
+------------------+-----------+--------------+----------------------------------------+
| mysql-bin.000097 | 541677824 | www   | test,mysql,information_schema |
+------------------+-----------+--------------+----------------------------------------+


//Copy the log file currently in use by the primary server is : mysql-bin.000097//


Check replication from server state
mysql>show slave statusg

 

//Copy primary server log files currently in use from the server are: mysql-bin.000103

 


//The log file currently in use is 000097, what I need to do is delete all the logs before No. 00095 (reserve out the log for the last few days)
Mysql>purge master logs to ' mysql-bin.000095;

 


#ll/usr/local/mysql/var/


//From the results, all logs prior to number 000097 have been deleted

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.