mysql-Slow Query log

Source: Internet
Author: User

First, Introduction to open the slow query log, you can let the MySQL record query over a specified time of the statement, through the location analysis performance bottlenecks, to better optimize the performance of the database system
Second, parameter description slow_query_log slow query on the status slow_query_log_file slow query log location (this directory requires the MySQL running account of the writable permissions, generally set to the MySQL data storage directory) Long_query_ Time query more than how many seconds to log
third, set the steps 1. View slow Query related parameters
Mysql> Show variables like'slow_query%';+---------------------------+----------------------------------+| variable_name | Value |+---------------------------+----------------------------------+| Slow_query_log | OFF | | Slow_query_log_file | /mysql/data/localhost-slow.log |+---------------------------+----------------------------------+MySQL> Show variables like'Long_query_time';+-----------------+-----------+| variable_name | Value |+-----------------+-----------+| Long_query_time |10.000000|+-----------------+-----------+
2 . Set method Method One: Global variable setting sets the Slow_query_log global variable to the "on" State
Set Global slow_query_log='on'
Set the location where the slow query log is stored
Set Global slow_query_log_file='/usr/local/mysql/data/cbx-slow.log';
The query is logged in more than 10 seconds
Set Global long_query_time=;
Method Two: Configuration file settings
==/usr/local/mysql/data/1
3 . Restart MySQL service mysqld restart
4. View the parameters after setting
 mysql> Show variables like  " slow_query%   " ;  +---------------------+--------------------------------+| variable_name | Value |+---------------------+--------------------------------+| Slow_query_log | On | | Slow_query_log_file | /usr/local/mysql/data/slow.log |+---------------------+--------------------------------+ mysql  > show variables like  " long_query_time   "  +-----------------+----------+| variable_name | Value |+-----------------+----------+| Long_query_time | 1.000000  |+-----------------+----------+ 
Iv. Testing 1 . Execute a slow query SQL statement MySQL Select Sleep (n); 2 . See if a slow query log is generated 3. ls/usr/local/mysql/data/cbx-slow.log4. If the log is present, MySQL turns on slow query settings successfully!

mysql-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.