MySQL Query Log

MySQL Query Log

MySQL不像Oracle会在源码中植入大量的调试入口,最近突然要调试一下MySQLSQL执行过程,于是上官方查了一下,发现只有一个叫做Query Log的机制。当开关被打开之后,所有执行的SQL Statement都会被记录下来,非常详细,基本能够达到调试的目的。这是官方给出的Query Log功能描述:

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data.)

 

 

打开MySQLQuery Log的方式有两个:

1.       在启动MySQL的时候加入以下启动参数:--log[=file_name] or -l [file_name] option

在版本5.1.6之前,记录下来的Query Log只能保存在MySQL内部的一张table中,而在5.1.6版本之后,Query Log既可以保存在table也可以保存在File中,数据库中会有一个参数叫做general_log,值为01,代表了Query Log的启动开关,我们可以在MySQL中执行”show variables like %log%” 可以看到所有跟log有关的参数

 

2.         另外一种方式就是在MySQL的配置文件my.ini末尾加上一行log=D:/temp_sql.log,这种方式似乎没有在官方文档中找到描述,但是却非常实用。

 

回想起来还是Oracle胆子比较大,居然直接把debug代码留在Release中,使得在运行时得到最大程度的指导错误调试和性能优化。现如今Oracle已经通过收购Sun拥有了MySQL,不知道这个开源免费的数据库今后会如何发展下去。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值