23
13

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.

Docker環境でMySQLのログを確認する

Posted at

まず、dockerのMySQLコンテナに入ります。
MySQLサーバにログインして、以下のようにgeneral_logの位置を確認します。

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

OFFになっているので、ONにします。
こうしないとファイルが出現しないようです。

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

MySQLからぬけて、var/lib/mysqlに移動します。ここのファイルの内容を参照すれば見れます。

root@55ca40b8744e:~# cd /var/lib/mysql
root@55ca40b8744e:/var/lib/mysql# cat 55ca40b8744.log 
Tcp port: 3306  Unix socket: /var/run/mysqld/mysqld.sock
Time                 Id Command    Argument
2020-12-18T17:18:27.044729+09:00	   26 Quit

先ほど MySQLのサーバを抜けたので、Quitしたと出ています。

試しにdeleteしたときのログは以下のように出ます。

2020-12-18T17:02:09.716428+09:00	   67 Prepare	DELETE FROM `TABLE` WHERE `table`.`id` = ?
2020-12-18T17:02:09.716513+09:00	   67 Execute	DELETE FROM `TABLE` WHERE `table`.`id` = 0
23
13
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
23
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?