重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了MySQL查询日志指的是什么意思,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
在蓝山等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、网站建设 网站设计制作按需搭建网站,公司网站建设,企业网站建设,高端网站设计,成都全网营销推广,外贸网站制作,蓝山网站建设费用合理。
1、查询日志记录了客户端的所有操作语句,二进制不包含查询数据的sql语句。
2、查询日志记录服务器收到的每一个查询或命令。无论这些查询或命令是否正确,甚至是否包含语法错误,查询日志都会记录下来。
记录格式为{Time、Id、Command、Argument}。也正是因为mysql服务器需要不断记录日志,打开查询日志会产生很大的系统费用。因此,Mysql默认关闭查询日志。
实例
a、启用通用查询日志 --演示环境 root@localhost[(none)]> show variables like '%version%'; +-------------------------+------------------------------+ | Variable_name | Value | +-------------------------+------------------------------+ | innodb_version | 5.5.39 | | protocol_version | 10 | | slave_type_conversions | | | version | 5.5.39-log | | version_comment | MySQL Community Server (GPL) | | version_compile_machine | x86_64 | | version_compile_os | Linux | +-------------------------+------------------------------+ --查看系统变量 root@localhost[(none)]> show variables like '%general%'; +------------------+----------------------------+ | Variable_name | Value | +------------------+----------------------------+ | general_log | OFF | | general_log_file | /var/lib/mysql/suse11b.log | +------------------+----------------------------+ --查看当前的通用日志,显示无日志文件 root@localhost[(none)]> system ls /var/lib/mysql/suse11b.log ls: cannot access /var/lib/mysql/suse11b.log: No such file or directory --设置变量general_log以开启通用查询日志 root@localhost[(none)]> set @@global.general_log=1; Query OK, 0 rows affected (0.00 sec) --再次查看通用日志文件已存在 root@localhost[(none)]> system ls /var/lib/mysql/suse11b.log /var/lib/mysql/suse11b.log root@localhost[(none)]> select * from tempdb.tb1; --执行查询 +------+------+ | id | val | +------+------+ | 1 | jack | +------+------+ --查看通用日志文件内容 root@localhost[(none)]> system more /var/lib/mysql/suse11b.log /usr/sbin/mysqld, Version: 5.5.39-log (MySQL Community Server (GPL)). started with: Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock Time Id Command Argument 141003 16:18:12 4 Query show variables like '%general%' 141003 16:18:55 4 Query select * from tempdb.tb1 b、更改通用查询日志位置 root@localhost[(none)]> exit Bye suse11b:~ # service mysql stop Shutting down MySQL... done suse11b:~ # mysqld --general_log_file=/tmp/suse11b.log --user=mysql & [1] 47009 suse11b:~ # ps -ef|grep mysql|grep -v grep mysql 47009 44514 1 16:22 pts/0 00:00:00 mysqld --general_log_file=/tmp/suse11b.log --user=mysql root 47053 44514 0 16:22 pts/0 00:00:00 grep mysql suse11b:~ # mysql root@localhost[(none)]> system ls /tmp/suse11b.log ls: cannot access /tmp/suse11b.log: No such file or directory root@localhost[(none)]> show variables like '%gener%'; +------------------+------------------+ | Variable_name | Value | +------------------+------------------+ | general_log | OFF | | general_log_file | /tmp/suse11b.log | +------------------+------------------+ root@localhost[(none)]> set global general_log=on; Query OK, 0 rows affected (0.01 sec) --此时从系统变量看出,通用日志已经到/tmp目录下 root@localhost[(none)]> show variables like '%gener%'; +------------------+------------------+ | Variable_name | Value | +------------------+------------------+ | general_log | ON | | general_log_file | /tmp/suse11b.log | +------------------+------------------+ --发布查询 root@localhost[(none)]> select count(*) from tempdb.tb1; +----------+ | count(*) | +----------+ | 1 | +----------+ --查看通用日志文件内容 root@localhost[(none)]> system more /tmp/suse11b.log mysqld, Version: 5.5.39-log (MySQL Community Server (GPL)). started with: Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock Time Id Command Argument 141003 16:30:03 1 Query show variables like '%gener%' 141003 16:30:09 1 Query select count(*) from tempdb.tb1 c、通用查询日志输出方式 --可以输出为文件,表以及不输出,即TABLE,FILE,NONE --系统变量log_output root@localhost[(none)]> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ --下面修改为输出为表方式 root@localhost[(none)]> set global log_output='TABLE'; Query OK, 0 rows affected (0.00 sec) root@localhost[(none)]> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ --发布查询 root@localhost[(none)]> select * from tempdb.tb1; +------+------+ | id | val | +------+------+ | 1 | jack | +------+------+ --Author: Leshami --Blog : http://blog.csdn.net/leshami root@localhost[(none)]> system more /tmp/suse11b.log mysqld, Version: 5.5.39-log (MySQL Community Server (GPL)). started with: Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock Time Id Command Argument 141003 16:30:03 1 Query show variables like '%gener%' 141003 16:30:09 1 Query select count(*) from tempdb.tb1 141003 16:31:00 1 Query show variables like 'log_output' 141003 17:00:48 1 Query set global log_output='TABLE' #通用查询日志输出到文件仅仅记录到全局变量的修改 --mysql.general_log记录了通用查询日志的信息 root@localhost[(none)]> desc mysql.general_log; +--------------+------------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +--------------+------------------+------+-----+-------------------+-----------------------------+ | event_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP | | user_host | mediumtext | NO | | NULL | | | thread_id | int(11) | NO | | NULL | | | server_id | int(10) unsigned | NO | | NULL | | | command_type | varchar(64) | NO | | NULL | | | argument | mediumtext | NO | | NULL | | +--------------+------------------+------+-----+-------------------+-----------------------------+ --从通用查询日志表里查看通用查询日志的内容 root@localhost[(none)]> select thread_id,command_type,argument from mysql.general_log; +-----------+--------------+---------------------------------------------------------------+ | thread_id | command_type | argument | +-----------+--------------+---------------------------------------------------------------+ | 1 | Query | show variables like 'log_output' | | 1 | Query | select * from tempdb.tb1 | | 1 | Query | desc mysql.general_log | | 1 | Query | select thread_id,command_type,argument from mysql.general_log | +-----------+--------------+---------------------------------------------------------------+ root@localhost[(none)]> show variables like 'log_output'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | TABLE | +---------------+-------+ --使用FILE,TABLE 2者混合输出通用日志 root@localhost[(none)]> set global log_output='file,table'; Query OK, 0 rows affected (0.00 sec) root@localhost[(none)]> select @@global.log_output; +---------------------+ | @@global.log_output | +---------------------+ | FILE,TABLE | +---------------------+ root@localhost[(none)]> insert into tempdb.tb1 values(2,'robinson'); Query OK, 1 row affected (0.06 sec) root@localhost[(none)]> commit; Query OK, 0 rows affected (0.01 sec) --验证结果,表和文件里边存在通用的日志记录 root@localhost[(none)]> system tail /tmp/suse11b.log|grep robinson 141003 17:41:54 2 Query insert into tempdb.tb1 values(2,'robinson') root@localhost[(none)]> select thread_id,command_type,argument from mysql.general_log -> where argument like '%robinson%'; +-----------+--------------+------------------------------------------------------------------------+ | thread_id | command_type | argument | +-----------+--------------+------------------------------------------------------------------------+ | 2 | Query | insert into tempdb.tb1 values(2,'robinson') | | 2 | Query | select thread_id,command_type,argument from mysql.general_log | | | | where argument like ''robinson'' | +-----------+--------------+------------------------------------------------------------------------+ d、关闭通用查询日志 --可以通过设置系统变量general_log来关闭通用查询日志,此时日志输出设置为FILE,TABLE root@localhost[(none)]> show variables like 'log_output'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | log_output | FILE,TABLE | +---------------+------------+ root@localhost[(none)]> set global general_log=off; Query OK, 0 rows affected (0.01 sec) root@localhost[(none)]> show variables like '%gener%'; +------------------+------------------+ | Variable_name | Value | +------------------+------------------+ | general_log | OFF | | general_log_file | /tmp/suse11b.log | +------------------+------------------+ root@localhost[(none)]> delete from tempdb.tb1 where id=2; Query OK, 1 row affected (0.12 sec) root@localhost[(none)]> commit; Query OK, 0 rows affected (0.00 sec) root@localhost[(none)]> system tail -n 1 /tmp/suse11b.log 141003 17:45:13 2 Query set global general_log=off root@localhost[(none)]> select thread_id,command_type,argument from mysql.general_log -> where argument like '%delete%'; Empty set (0.00 sec) --从上面的演示可知,尽管我们设置了log_output为FILE,TABLE,但general_log为OFF,通用日志无任何记录产生 root@localhost[(none)]> set global log_output=none; Query OK, 0 rows affected (0.00 sec) root@localhost[(none)]> set global general_log=1; Query OK, 0 rows affected (0.00 sec) root@localhost[(none)]> truncate table tempdb.tb1; Query OK, 0 rows affected (0.01 sec) root@localhost[(none)]> system tail -n 1 /tmp/suse11b.log Time Id Command Argument --通过上面的演示,在log_output=none,general_log=on的清下下无任何通用日志输出。
感谢你能够认真阅读完这篇文章,希望小编分享的“mysql查询日志指的是什么意思”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!