zoukankan      html  css  js  c++  java
  • MySQL Query Log

    MySQL不像Oracle会在源码中植入大量的调试入口,最近突然要调试一下MySQL的SQL执行过程,于是上官方查了一下,发现只有一个叫做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.)

    打开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,不知道这个开源免费的数据库今后会如何发展下去。

  • 相关阅读:
    Flutter移动电商实战 --(40)路由_Fluro的全局注入和使用方法
    Flutter移动电商实战 --(39)路由_Fluro的路由配置和静态化
    Flutter移动电商实战 --(38)路由_Fluro中Handler编写方法
    Flutter移动电商实战 --(37)路由_Fluro引入和商品详细页建立
    网络基础:NetBIOS
    linux 定时任务
    linux useradd 命令基本用法
    Git undo 操作
    Git 查看文件的历史
    Ubuntu14.04安装postgresql9.4
  • 原文地址:https://www.cnblogs.com/weaver1/p/3337854.html
Copyright © 2011-2022 走看看