MySQL turns on binlog log and slow query log

Source: Internet
Author: User

1) First, why should I turn on Binlog log and slow query log?

Binlog log will be recorded in the database, so adding and deleting the operation, when accidentally delete, empty data, or database system error, this time you can use the Binlog log to restore the database, simply, is a record backup of things

Slow query log Slow_query_log, this thing is used to record query slow SQL statements, query the log to find which SQL statement is slow, then you can do database or SQL statement or program optimization, simply is an optimization helper

Ps:binlog log should be open all the time (because you do not know which day the database will be collapsed, or one day will mistakenly delete a thing), slow query log can not open, when the site is slow, need to optimize, you can open slow query to do an auxiliary

2) How to open Binlog log

Add a Binlog configuration under My.cnf [mysqld] (note that it must be added under [mysqld], if not in [Mysqld_safe] or other locations), configure as follows:

log-bin=mysql-bin

PS: The above mysql-bin is actually the Binlog log file prefix, like the above set is Mysql-bin (you can change to mysql_bin or binlog or anything else), it will be in the/var/lib/mysql/ Generate mysql-bin.000001,mysql-bin.000002,mysql-bin.000003 (default location) ... and other log files

3) Turn on slow query log

Modify Configuration Method One (temporary, restart mysqld after automatic recovery ):

Global log_slow_queries=global slow_launch_time=10;

Modify Configuration Method Two (permanent):

Add a Binlog configuration under My.cnf [mysqld] (note that it must be added under [mysqld], if not in [Mysqld_safe] or other locations), configure as follows:

log-slow-queries=/var/log/mysqld-slow. Log long_query_time=2

The first configuration is the log file location, the second configuration is the time configuration of the slow query (in seconds), and query statements that execute longer than this time are recorded

MySQL turns on binlog log and slow query log

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.