6
1

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 3 years have passed since last update.

#前提
MySQLにおけるクエリログの見方を忘れがちなのでメモします。

MySQL8
#本題
MySQLのクエリログはgeneral_logと言う設定をONにすることにより、
すべてのクエリをログに吐かせることができる。

まずは、general_logの設定確認。

mysql> show variables like 'general_log%';
+------------------+---------------------------------+
| Variable_name    | Value                           |
+------------------+---------------------------------+
| general_log      | OFF                             |
| general_log_file | /var/lib/mysql/2a4a9fa16d2e.log |
+------------------+---------------------------------+
2 rows in set (0.00 sec)

デフォルトでは恐らくOFFになっているため、ONに変更します。

mysql> set global general_log = on;
Query OK, 0 rows affected (0.02 sec)

確認。

mysql> show variables like 'general_log%';
+------------------+---------------------------------+
| Variable_name    | Value                           |
+------------------+---------------------------------+
| general_log      | ON                              |
| general_log_file | /var/lib/mysql/2a4a9fa16d2e.log |
+------------------+---------------------------------+
2 rows in set (0.01 sec)

試しにクエリを投げてみます。

mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.01 sec)
$ cat /var/lib/mysql/2a4a9fa16d2e.log

2020-10-24T00:00:00.278525Z    19 Query show variables like 'general_log%'
2020-10-24T00:00:00.802232Z    18 Query select 1

※ログの分だけディスクを食うので注意。

6
1
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
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?