MySQL slow query logging and Mysqlbinlog configuration tutorial

Source: Internet
Author: User
Tags datetime

MySQL can record all slow queries and record the SQL statements in the specified file, or you can add updates through the Mysqlbinlog record, or you can restore the database through Mysqlbinlog.

MySQL Slow query record

Edit My.cnf File

Linux is usually in/etc/my.cnf or/usr/local/mysql/etc/my.cnf

Windows find it Yourself

In the [Mysqld] tab, add the following:

The code is as follows Copy Code

Log-slow-queries=/var/lib/mysql/slow.log #慢日志保存路径, the file itself new
long_query_time=2 #超过2秒的查询
; Log-queries-not-using-indexes #记录没有使用索引的查询

Turn on MySQL incremental logging

Also add the following in the [Mysqld] label below

The code is as follows Copy Code

log-bin=mysqlbin# name to pick
Binlog_cache_size = 4M
Binlog_format = MIXED
Max_binlog_cache_size = 256M
Max_binlog_size = 1g# log size
expire_logs_days = 30# Record 30 days of log
Mysqlbinlog's log is usually in/var/lib/mysql.

Log some simple query export operations, where mysqlbin.000001 is a log file inside

The code is as follows Copy Code

Mysqlbinlog--start-datetime= "2013-09-10 00:00:00"--stop-datetime= "2013-09-13 23:59:59" mysqlbin.000001 >/root/ Log.txt

You can also use these records for database restore

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.