0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【MySQL】MySQLを再起動せずにスロークエリログを出力する方法

Posted at

本番環境など再起動できないサーバーでスロークエリログを取得するにはmy.confの設定ではなく、以下の方法で出力できる。

スロークエリログの出力を開始する

set global slow_query_log = 1;

スロークエリログの出力を停止する

set global slow_query_log = 0;

スロークエリログの出力先を指定する

set global slow_query_log_file='/var/lib/mysql/slow_query.log';

何秒以上のクエリをログ出力するか設定する

set global long_query_time = 1;

※ここでは1秒以上のクエリを出力する設定をしているが、0.1秒なども設定可能。

スロークエリに関する設定の確認

mysql> show variables like 'slow_query%';
+---------------------+-------------------------------+
| Variable_name       | Value                         |
+---------------------+-------------------------------+
| slow_query_log      | ON                            |
| slow_query_log_file | /var/log/mysql/slow_query.log |
+---------------------+-------------------------------+

mysql> show variables like 'long%';
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 0.100000 |
+-----------------+----------+

※long_query_timeは一度quitで抜けて入りなおさないと表示が反映されないので注意。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?