【问题标题】:How to trace MySql queries using MySql-Proxy?如何使用 MySql-Proxy 跟踪 MySql 查询?
【发布时间】:2011-01-12 17:18:36
【问题描述】:

我刚刚下载了 mysql-proxy 并创建了这个脚本 lua(在 Mysql 文档中找到):

function read_query(packet)
   if string.byte(packet) == proxy.COM_QUERY then
     print("QUERY: " .. string.sub(packet, 2))
   end
 end

这是我正在使用的命令行:

mysql-proxy -P localhost:1234 -b localhost:3306 --proxy-lua-script=profile.lua --plugins=proxy

当我运行一个简单的查询(比如“select * from table1”)时,报这个错误:“failed: .\lua-scope.c:241: stat(C:...\profile.lua) failed : 没有错误 (0)"

注意:如果我在没有 lua 脚本的情况下运行 mysql-proxy,则不会发生错误。

我需要安装一些东西来让 mysql-proxy 和查询跟踪工作吗?

我的环境是 Windows 7 Professional x64。

抱歉英语不好。

【问题讨论】:

    标签: mysql lua mysql-proxy


    【解决方案1】:

    您遇到的错误是由 --proxy-lua-script 指向 mysql-proxy 找不到的文件引起的。要么你输入了错误的名称,要么你输入了错误的路径,要么你期望它在你的 CWD 中并且它不存在。或者实际上,更仔细地查看整个错误,mysql-proxy 本身似乎可以在 CWD 中看到文件,但其中一个底层模块不喜欢它(可能是因为 mysql-proxy 以某种方式更改了 CWD ?)

    尝试将 profile.lua 保存到 C: 驱动器的根目录并尝试不同版本的选项,如下所示:

    --proxy-lua-script=c:\profile.lua
    --proxy-lua-script=\profile.lua
    --proxy-lua-script=/profile.lua
    

    其中一个可能会起作用

    【讨论】:

    • 成功了! --proxy-lua-script=c:\profile.lua 谢谢!
    【解决方案2】:

    简单查询日志lua脚本:

    require("mysql.tokenizer")
    
    local fh = io.open("/var/log/mysql/proxy.query.log", "a+")
    fh:setvbuf('line',4096)
    local the_query = "";
    local seqno = 0;
    
    function read_query( packet )
        if string.byte(packet) == proxy.COM_QUERY then
            seqno = seqno + 1
            the_query = (string.gsub(string.gsub(string.sub(packet, 2), "%s%s*", ' '), "^%s*(.-)%s*$", "%1"))
            fh:write(string.format("%s %09d %09d : %s (%s) -- %s\n",
                os.date('%Y-%m-%d %H:%M:%S'),
                proxy.connection.server.thread_id,
                seqno,
                proxy.connection.client.username,
                proxy.connection.client.default_db,
                the_query))
            fh:flush()
            return proxy.PROXY_SEND_QUERY
        else
            query = ""
        end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 2019-10-18
      • 2020-11-07
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多