一、通用查詢日誌:記錄創建的客戶端鏈接和執行的語句,通用查詢日誌默認狀況下不是開啓的,通用查詢日誌是以文本方式存放的mysql
當須要採樣分析的時候手工開啓:sql
SET Global general_log=1; 在全局模式下開啓通用查詢日誌1是打開,0是關閉
//--不建議使用在配置文件裏面修改
[mysqld]
general-log-file=path/[filename] 查詢日誌保存的位置
general-log=1 開啓通用查詢日誌dom
默認存在在數據目錄下 [root@localhost mysql]# ls auto.cnf ib_logfile0 king mysql mysql_bin.000002 mysql_bin.000004 mysql_bin.index performance_schema utf8 ibdata1 ib_logfile1 localhost.localdomain.pid mysql_bin.000001 mysql_bin.000003 mysql_bin.000005 mysql.sock test world mysql> set global general_log=1 ; Query OK, 0 rows affected (0.07 sec) [root@localhost mysql]# ls auto.cnf ib_logfile0 king localhost.log mysql_bin.000001 mysql_bin.000003 mysql_bin.000005 mysql.sock test world ibdata1 ib_logfile1 localhost.localdomain.pid mysql mysql_bin.000002 mysql_bin.000004 mysql_bin.index performance_schema utf8
[root@localhost mysql]# tail -f localhost.log --查看查詢日誌 -f實時顯示查看socket
/usr/local/mysql/bin/mysqld, Version: 5.6.23-log (MySQL Community Server (GPL)). started with:spa
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
160328 10:39:24 4 Query show databases
160328 10:39:31 4 Query SELECT DATABASE()
4 Init DB world
4 Query show databases
4 Query show tables
160328 10:39:37 4 Query show tables
160328 10:39:43 4 Query SELECT DATABASE()
4 Init DB king
4 Query show databases
4 Query show tables
4 Field List b
4 Field List pet
4 Field List student
4 Field List t
4 Field List test
4 Field List w
160328 10:39:46 4 Query show tables
160328 10:39:58 4 Query select * from student
160328 10:40:53 4 Query desc t日誌
160328 10:43:08 4 Query set global general_log=0code
mysql> set global general_log=0;
Query OK, 0 rows affected (0.01 sec)orm
二、刪除通用查詢日誌:blog
通用查詢日誌可能會不斷增加,一般是採樣分析這樣的特別工做纔開啓,其餘的時候則關閉。無用的查詢日誌要及時刪除it
刪除方法爲:
mysql>set=global general_log=0; [root@localhost mysql]# rm -rf /var/lib/mysql/host.log