MySQL binary log deletion and Restoration

Source: Internet
Author: User
Tags mysql slow query log
What should I do if I don't want these files? 1: There is only one mysql server. You can simply comment out this option. Vietcmy. cnf

What should I do if I don't want these files? 1: There is only one mysql server. You can simply comment out this option. Vi/etc/my. cnf

Vi/etc/my. cnf
[Mysqld]
Datadir =/var/lib/mysql
Socket =/var/lib/mysql. sock
# Default to using old password format for compatibility with mysql 3.x
# Clients (those using the mysqlclient10 compatibility package ).
# Old_passwords = 1
Table_cache = 300
Default-character-set = utf8
Log =/var/lib/mysqllog/mysql. log
Log-bin =/var/lib/mysqllog/log-bin
Log-slow-queries =/var/lib/mysqllog/slowquery. log
Long_query_time = 2

[Mysql. server]
User = mysql
Basedir =/var/lib

[Mysqld_safe]
Log-error =/var/log/mysqld. log
Pid-file =/var/run/mysqld. pid
The content in the black body is added. Log-error =/var/log/mysqld. log in italics
Mysql has the following types of logs:
Error log:-log-err
Query log:-log
Slow query log:-log-slow-queries
Update log:-log-update my version is no longer used, and the update operation is also recorded in the query log. After setting, the error log contains an error message, but it does not affect the usage.
Binary log:-log-bin


Appendix:

// Display binary logs on all hosts
Mysql> show master logs;
// Delete binary logs on all hosts
Mysql> reset master;
// Delete all binary logs created before the binary-log.xxx
Mysql> purge master logs to 'binary-log. XXX ';
// Only logs of the last 6 days are retained, and all previous logs are deleted.
Find/var/intra-type f-mtime + 6-name "*. log"-exec rm-f {}\;
// Use the key in the upper-left corner of the keyboard (that is, under Esc) to enclose it, which indicates a command. -1d is yesterday, and so on-1 m is last month, etc.
Day = '/bin/date-v-1d + % Y % m % d ';
// Rename the file
Mv xxx. log xxx-$ {day}. log;
// The username and password of the database must be added here to update logs (including binary logs and query logs)
Mysqladmin flush-logs

Open mysql slow query log records

Mysql slow query logs are very useful for queries with tracing problems. We can analyze the resource-consuming SQL statements in the current program. How can we open mysql slow query log records?
In fact, it is very easy to open the slow query log of mysql, just in the mysql configuration file (windows system is my. ini, linux is my. the following code is added to [mysqld] of cnf:

Log-slow-queries =/var/lib/mysql/slowquery. log
Long_query_time = 2

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.