How to open a slow query in a MySQL database in Linux

Source: Internet
Author: User
Tags mysql database

Here's how to fix it:
Original MY.CNF configuration file:

The code is as follows Copy Code
[Client]
Default-character-set=utf8
[MySQL]
Default-character-set=utf8
[Mysqld]
Slow-query-log-file=/var/log/mysql/slow.log
long_query_time=0.03
Log-queries-not-using-indexes
Character-set-server=utf8
Collation-server=utf8_unicode_ci
init-connect= ' SET NAMES UTF8 '
max_connections=3000
.....

I'm not finished here, just sticking out the key.

Modified MY.CNF configuration file:

The code is as follows Copy Code
[Client]
Default-character-set=utf8
[MySQL]
Default-character-set=utf8
[Mysqld]
Slow_query_log=on
Slow-query-log-file=/var/log/mysql/slow.log
long_query_time=0.03
Log-queries-not-using-indexes
Character-set-server=utf8
Collation-server=utf8_unicode_ci
init-connect= ' SET NAMES UTF8 '
max_connections=3000
.....

After modifying the configuration file, remember to save the restart MySQL service.

Of course, you can also open the slow query directly in MySQL:

The code is as follows Copy Code
Mysql>set global slow_query_log= ' on ';

Query slow query is open:

The code is as follows Copy Code
Mysql> Show variables like "Slow_query_log";
+----------------+-------+
| variable_name | Value |
+----------------+-------+
| Slow_query_log | On |
+----------------+-------+
1 row in Set (0.00 sec)

Of course, you can also use the following command:

The code is as follows Copy Code
Mysql> Show variables like "%query%";
+------------------------------+-------------------------+
| variable_name | Value |
+------------------------------+-------------------------+
| binlog_rows_query_log_events | Off |
| Ft_query_expansion_limit | 20 |
| Have_query_cache | YES |
| Long_query_time | 0.030000 |
| Query_alloc_block_size | 8192 |
| Query_cache_limit | 1048576 |
| Query_cache_min_res_unit | 4096 |
| Query_cache_size | 1048576 |
| Query_cache_type | Off |
| Query_cache_wlock_invalidate | Off |
| Query_prealloc_size | 8192 |
| Slow_query_log | On |
| Slow_query_log_file | /var/log/mysql/slow.log |
+------------------------------+-------------------------+
Rows in Set (0.00 sec)

Finally, check that the/var/log/mysql/slow.log users and groups are MySQL, permissions are writable, and see if the file size of the Slow.log has changed, so that the slow query is open successfully, and has been recorded in the log file.

Original from: blog.slogra.com

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.