LoginSignup
14
14

More than 5 years have passed since last update.

[MySQL]スロークエリログの出力設定

Posted at

毎回ググってしまうので・・・

スロークエリとしての判定時間を設定

mysql> SHOW GLOBAL VARIABLES LIKE '%query_time%' ;
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.24 sec)

mysql> SET GLOBAL long_query_time = 0.5 ;
Query OK, 0 rows affected (0.25 sec)

mysql> SHOW GLOBAL VARIABLES LIKE '%query_time%' ;
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 0.500000 |
+-----------------+----------+
1 row in set (0.00 sec)

ログ出力するように


mysql> SHOW GLOBAL VARIABLES LIKE '%slow_query%' ;
+---------------------+--------------------------------+
| Variable_name       | Value                          |
+---------------------+--------------------------------+
| slow_query_log      | OFF                            |
| slow_query_log_file | /var/lib/mysql/hoge-slow.log |
+---------------------+--------------------------------+
2 rows in set (0.00 sec)

mysql>  SET GLOBAL slow_query_log = 'ON' ;
Query OK, 0 rows affected (0.26 sec)


mysql> FLUSH LOGS ;
Query OK, 0 rows affected (0.10 sec)

mysql> SHOW GLOBAL VARIABLES LIKE '%slow_query%' ;
+---------------------+--------------------------------+
| Variable_name       | Value                          |
+---------------------+--------------------------------+
| slow_query_log      | ON                             |
| slow_query_log_file | /var/lib/mysql/hoge-slow.log |
+---------------------+--------------------------------+
2 rows in set (0.00 sec)


mysql> FLUSH LOGS ;
14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14