MySQL Query Log

MySQL不像Oracle会在源码中植入大量的调试入口,最近忽然要调试一下MySQL的SQL执行过程,因而上官方查了一下,发现只有一个叫作Query Log的机制。当开关被打开以后,全部执行的SQL Statement都会被记录下来,很是详细,基本可以达到调试的目的。这是官方给出的Query Log功能描述:html

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.mysql

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.)sql

 

 

打开MySQL的Query 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,值为0或1,表明了Query Log的启动开关,咱们能够在MySQL中执行”show variables like %log%” 能够看到全部跟log有关的参数性能优化

 

  1. 另一种方式就是在MySQL的配置文件my.ini末尾加上一行”log=D:/temp_sql.log”,这种方式彷佛没有在官方文档中找到描述,可是却很是实用。

 

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

相关文章
相关标签/搜索