Mysql start / view slow query log

Keywords: MySQL SQL Programming Windows

Mysql view slow query log

0. environment

  • windows10
  • mysql5.7

1. demand

In normal programming, for a slow SQL, we may need to view the "slow query" log of the SQL. We can get some inspiration from this log, so as to optimize the SQL and reduce the query time. But how to open and search the slow query log of mysql?

2. actual combat

  • Default log file
    In MySQL 5.7, slow query log is enabled by default, but the log file name may not be what we want. We query as follows:
mysql> show variables like '%quer%';
+----------------------------------------+--------------------------+
| Variable_name                          | Value                    |
+----------------------------------------+--------------------------+
| binlog_rows_query_log_events           | OFF                      |
| ft_query_expansion_limit               | 20                       |
| have_query_cache                       | YES                      |
| log_queries_not_using_indexes          | OFF                      |
| log_throttle_queries_not_using_indexes | 0                        |
| long_query_time                        | 10.000000                |
| 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                    | ICOS-20180710CX-slow.log |
+----------------------------------------+--------------------------+
15 rows in set, 1 warning (0.00 sec)

You can see that the default slow query log file name is ICOS-20180710CX-slow.log. And the slow query log is open.

  • View the contents of my.ini file

  • Modify the contents of my.ini file [note the path under windows]

  • Finally, restart mysql service and view the slow query log

3. notes

Be sure to note that the content of my.ini is in mysql data directory, not mysql installation directory. [sometimes we put the data directory page in the installation directory, which makes the illusion that my.ini file is in the installation directory]

Posted by hadoob024 on Sat, 04 Jan 2020 10:27:06 -0800