I have an intermittent bug that I'm trying to track down, and I'd like to capture only MySQL queri开发者_JAVA技巧es 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,
JDNot 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.
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...
精彩评论