查询日志的作用是记录所有客户端发来的sql语句,也就是记录客户端的所有操作
Log参数将要过时,现在用general_log来代替
打开查询日志功能
mysql> showvariables like "%log";
+----------------+-------+
| Variable_name| Value |
+----------------+-------+
| back_log| 50|
| general_log| OFF|
| log| OFF|
| relay_log||
| slow_query_log | OFF|
| sync_binlog| 0|
+----------------+-------+
6 rows in set (0.01 sec)
mysql> set global general_log=1;
Query OK, 0 rows affected (0.18 sec)
mysql> set globallog=1;
Query OK, 0 rows affected, 1 warning (0.00sec)
mysql> showvariables like "%log";
+----------------+-------+
| Variable_name| Value |
+----------------+-------+
| back_log| 50|
| general_log| ON|
| log| ON|
| relay_log||
| slow_query_log | OFF|
| sync_binlog| 0|
+----------------+-------+
6 rows in set (0.00 sec)
也可以在my.cnf中添加参数
general_log=1
general_log_file=/tmp/chenzhongyang.log这样来设定
mysql> show variables like"%file";
+---------------------+-----------------------------------------+
| Variable_name| Value|
+---------------------+-----------------------------------------+
| ft_stopword_file| (built-in)|
| general_log_file| /tmp/chenzhongyang.log|
| init_file||
| local_infile| ON|
| pid_file|/usr/local/mysql/var/test4.wolf.org.pid |
| relay_log_info_file | relay-log.info|
| slow_query_log_file |/usr/local/mysql/var/test4-slow.log|
+---------------------+-----------------------------------------+
查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/
查看日志文件的内容
[root@test4 ~]# tail -f/tmp/chenzhongyang.log
/usr/local/mysql/libexec/mysqld, Version:5.1.70-log (Source distribution). started with:
Tcp port: 3306Unix socket: /tmp/mysql.sock
TimeId CommandArgument
130903 16:09:431 Connectroot@localhost on
1 Queryselect@@version_comment limit 1
130903 16:10:141 Queryshow variables like "%file"
130903 16:12:091 Queryselect * fromtt
130903 16:12:161 QuerySELECT DATABASE()
1 Init DBtest
130903 16:12:181 Queryselect * fromtt
一般情况下我们不打开查询日志功能,因为他对系统效率的影响很大
管理查询日志文件
一般的日志文件会很大,所以要处理日志
[root@test4 ~]# mysqladminflush-logs;刷新日志所有日志文件
出处:http://wolfword.blog.51cto.com/4892126/1287978