如何在mysql-proxy上使用Lua脚本记录SQL错误和警告 [英] How to log SQL errors AND warnings with a Lua script on mysql-proxy

查看:322
本文介绍了如何在mysql-proxy上使用Lua脚本记录SQL错误和警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试目的,我想在服务器级别记录MySQL返回的SQL错误和警告消息以及相应的查询.

For debug purposes, I want to log SQL errors and warnings messages returned by MySQL, and corresponding queries, at server-level.

我发现了两个有用的Lua脚本:

I've found two useful Lua scripts :

https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua https://github.com/patrickallaert/MySQL-Proxy-scripts-for-开发者(debug.lua)

https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua https://github.com/patrickallaert/MySQL-Proxy-scripts-for-devs (debug.lua)

允许使用MySQL代理记录错误.但我仍在寻找记录警告的方法. 我对mysql-proxy LUA脚本没有信心.有人可以告诉我该怎么做吗?

which allow to log errors with MySQL Proxy. But I'm still looking for a way to log warnings. I'm not confident with mysql-proxy LUA-scripting. Can someone indicate me how to do this ?

这个问题:将警告记录到表中似乎已经结束,但不幸的是提供的链接已消失,我找不到内容.

This question : Log warnings into a table seems to be close, but unfortunately the provided link is dead and I can not find the content.

推荐答案

我终于研究了文学研究的主题,并开发了适合我的Lua脚本.

I finally examined the subject in studying literature and developed the Lua script that suits me.

我首先提到的脚本( https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua )是一个好的开始点,但是:

The script I mentioned first (https://github.com/koopa/mysql-proxy-log-error-queries/blob/master/mysql-proxy-log-error-queries.lua) was a good starting point, but :

  • 它仅记录错误,不记录警告.最初,它管理一个错误标志",如果客户端的查询返回错误,则将其设置为true.我进行了更改,以便记录每个SHOW WARNINGS返回某些内容(错误,警告或注释)的查询.

  • It only logs errors and not warnings. Originally it manages an 'error flag' which is set to true if the client's query returns an error. I changed that in order to log every query for which SHOW WARNINGS returns something (Errors, Warnings or Notes).

它在表中插入了错误日志行.这可能很好,但可能会使客户端感到困惑,因为插入日志行会清除显示警告"查询所显示的消息.也许可以通过打开新会话或连接来解决此问题,但是我选择将事件记录到一个简单的文本文件中.其次,由于错误消息或原始查询中可能包含简单的引号',因此原始脚本中的插入查询可能会生成语法错误.

It inserted errors log lines into a table. It could be nice but can be quite confusing for the client, because inserting the log line clears the messages shown by 'show warnings' query. There's probably a way to fix that, opening a new session or connexion... but I choosed to log events into a simple text file. Secondarily, the insert query in the original script can generate a syntax error because of the simple quotes ' possibly contained in the error message or original query.

在记录所有警告时必须注意一点:所有查询都不会清除警告/注释队列.因此,SHOW WARNINGS可以在非警告生成查询之后返回由上一个查询生成的结果集. 为了解决这个问题,我使用了一种肮脏的方法:检测到查询后,我注入一个错误的查询,我知道该查询会生成错误消息;在我忽略此错误消息之后.这是一种清除"警告和注释的方法...

There is a point at which we must be careful when logging all warnings : all queries don't clear the warnings/notes queue. So SHOW WARNINGS can return a resultset generated by a previous query after a non-warning-generating query. To fix that, I use a dirty method : after detecting a query, I inject a bad query for which I know it will generate an error message; after what I ignore this error message. It's a way to "clear" warnings and notes...

这篇关于如何在mysql-proxy上使用Lua脚本记录SQL错误和警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆