3

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

Community
  • 1
  • 1
Jonathan Day
  • 18,519
  • 10
  • 84
  • 137

2 Answers2

1

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

Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
  • Thanks @garvey - I'd rather not introduce code to trap the error since this is a production system, but it may be the best answer. Magento does have an ORM layer via Zend_DB, so it could be done there. – Jonathan Day May 26 '11 at 14:02
1

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.

Johan
  • 74,508
  • 24
  • 191
  • 319
  • Thanks @johan - I don't see how the ronaldbradford link is helpful, am I missing something? are you suggesting that I could include "rollback" or something as a regex string? – Jonathan Day May 26 '11 at 13:58
  • @Jonathan, yes that's exactly what I'm suggesting. – Johan May 26 '11 at 14:03