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