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

MySQLのクエリログを収集したいときは

Posted at

MySQLでログの設定を行いたい

自分用メモです。

my.cnfの場所を調べる

$ mysql --help | grep my.cnf
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf 

左から順に呼ばれていく。
環境を汚したくないので今回は /usr/local/etc/my.cnf をいじる。

my.cnf設定

[mysqld]
# ...
general_log=1
log_output=FILE
general_log_file=/var/log/mysql/query.log
# ...

上記を追記する。

反映確認

show variables like '%general_log%';
Variable_name Value
general_log ON
general_log_file /var/log/mysql/query.log

上記方法でダメなときは

set global general_log='ON';

のように直接書き換えてみる。

ログ確認

$ tail -f /var/log/mysql/query.log
Tcp port: 3306  Unix socket: /var/lib/mysql/mysql.sock
Time                 Id Command    Argument
191125 21:29:31	  137 Query	SHOW VARIABLES LIKE '%log%'

ログが流れていくことが確認できる。

3
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
3
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?