[mysql@localhost ~]# mysqld --log=/var/log/mysql.log
mysql> show VARIABLES where variable_name like 'general_log%';
+------------------+-------------------------------+
| Variable_name | Value |
+------------------+-------------------------------+
| general_log | OFF |
| general_log_file | /APP/mysql-data/localhost.log |
+------------------+-------------------------------+
2 rows in set (0.00 sec)
mysql> set GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.01 sec)
mysql> show VARIABLES where variable_name like 'general_log%';
+------------------+-------------------------------+
| Variable_name | Value |
+------------------+-------------------------------+
| general_log | ON |
| general_log_file | /APP/mysql-data/localhost.log |
+------------------+-------------------------------+
2 rows in set (0.00 sec)
mysql> set GLOBAL general_log = 'OFF';
Query OK, 0 rows affected (0.05 sec)
[mysql@localhost ~]# tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings
[mysql@localhost ~]# vim query_monitor.sh
#!/bin/sh
#
# MySQL 패킷 살펴보기
#
INTERFACE="eth0"
PORT="3306"
tcpdump -i $INTERFACE -s 0 -l -w - dst port $PORT | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'