一、监控mysql执行的所有sql
1.编辑my.cnf文件,在[mysqld]下面加上一行配置,重启mysql服务,跟踪下面配置制定的文件,之后执行的sql都会在该文件里
log =
/usr/local/mysql/data/mysql_file
.log
#文件位置自定义
|
注意:据我目前测试,这个文件必须在${MYSQL_HOME}/data/目录下(放在和mysql-bin.0000N同一个目录下,该目录存放msyql的binlog),如果在其他地方都不会生成这个日志文件,跟踪日志发现报以下错误:[ERROR] Could not use /home/card/mysql.log for logging (error 13). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it. 可能是用户的权限问题,有兴趣的可以自行研究。
之后在在进入msyql,执行sql的时候,所有的sql语句都会进入到mysql_file.log。