是否可以配置 MySQL 日志记录,使其仅报告已回滚的查询?

发布于 2024-11-09 21:05:54 字数 565 浏览 6 评论 0原文

我有一个间歇性错误 我正在尝试追踪,并且我只想捕获失败导致回滚的 MySQL 查询。我不需要完整的 一般查询二进制 日志,因为其中会有数百万个条目要排序的干草堆 通过。

这个解决方案这样的解决方案(除了MySQL)将是完美的。

TIA,
京东

I have an intermittent bug that I'm trying to track down, and I'd like to capture only MySQL queries that fail resulting in a rollback. I don't want a full general query or binary log because there would be millions of entries in the haystack to sort through.

Something like this solution except for MySQL would be perfect.

TIA,
JD

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

|煩躁 2024-11-16 21:05:54

不是直接回答您的问题,但实用程序 mysqlbinlog 可以从二进制日志中提取数据。

请参阅:此页面中的用户评论: http://dev. mysql.com/doc/refman/5.5/en/binary-log.html
此页面: http://ronaldbradford.com/ blog/mysql-dml-stats-per-table-2009-09-09/

这是 mysqlbinlog 的官方文档,这可能会帮助您获取所需的信息。

Not a direct answer to your question, but the utility mysqlbinlog can extract data from the binary log.

See: the user comments in this page: http://dev.mysql.com/doc/refman/5.5/en/binary-log.html
And this page: http://ronaldbradford.com/blog/mysql-dml-stats-per-table-2009-09-09/

Here's the official documentation for mysqlbinlog, which might help you get the info you need.

混吃等死 2024-11-16 21:05:54

在 MySQL 中这是非常困难的(或者也许是不可能的)。您可以用 PHP 来完成。如果您不使用像 mysql_query 这样的低级函数,而使用像 ->query() 这样的高级方法,您可以向它们添加逻辑。如果查询失败(例如返回 false),请将其添加到日志中。对不起我的英语。

Zend_DB 注意:

class My_DB extends Zend_DB {
    public function insert($data) {
        try {
            parent::insert($data);
        } catch (Exception $e) {
            // put $e->getMessage() to log
        }
    }
}

您可以覆盖不同的方法,例如更新、查询等......

In MySQL it is very difficult (or maybe impossible). You can do it in PHP. If you don't use low functions like mysql_query and you use high methods like ->query(), you can add logic to theirs. If query failed (return false for example), add it to log. Sorry for my english.

Note for Zend_DB:

class My_DB extends Zend_DB {
    public function insert($data) {
        try {
            parent::insert($data);
        } catch (Exception $e) {
            // put $e->getMessage() to log
        }
    }
}

You can overwrite different methods, such as update, query and others...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文