查詢日誌的作用是記錄所有用戶端發來的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