是否可以配置MySQL日志记录,以便它只报告已回滚的查询?

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

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

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.