mysql:通用查询日志general_log

1、通用查询日志:记录建立的客户端连接和执行的语句,通用查询日志默认情况下不是开启的,通用查询日志是以文本方式存放的

当需要采样分析的时候手工开启:

SET Global general_log=1; 在全局模式下开启通用查询日志1是打开,0是关闭
//--不建议使用在配置文件里面修改
[mysqld]
general-log-file=path/[filename] 查询日志保存的位置
general-log=1 开启通用查询日志

默认存在在数据目录下
[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实时显示查看

/usr/local/mysql/bin/mysqld, Version: 5.6.23-log (MySQL Community Server (GPL)). started with:

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=0

mysql> set global general_log=0;
Query OK, 0 rows affected (0.01 sec)

 2、删除通用查询日志:

通用查询日志可能会不断增长,通常是采样分析这样的特别工作才开启,其他的时候则关闭。无用的查询日志要及时删除

删除方法为:

mysql>set=global general_log=0;
[root@localhost mysql]# rm -rf /var/lib/mysql/host.log

 

原文地址:https://www.cnblogs.com/1021lynn/p/5328146.html