tags:

views:

136

answers:

2

I can log all the mysql queries by enabling the general log. But it does not show the failed queries.

Is there a way to save failed queries as well?

A: 

You can log ALL queries by setting the sql_log_off variable to 0 (you should have super privilegies)

or you can log failed queries by PHP:

  function sql_query($data)
  {
      $sql = mysql_query($data);
      if($sql == FALSE){
           //do some logging here.
           $fh = fopen("log.txt", 'a') or die("can't open file");
           fwrite($fh, "\n MYSQL ERROR @".microtime(true).": QUERY:".$data."\n");
      }
      return $sql;
  }
afftee
Always remember to close file pointers, and a cleaner method would be to use `file_put_contents('log.txt', "\nError message", FILE_APPEND);`
Tatu Ulmanen
A: 

It does show failed queries. There is no easy way of segregating them.

mhughes
I am totally surprised to see that general log is really recording everything! even the failed queries. The slow and binary logs won't have those queries. Correct?
shantanuo
slow query log only shows slow queries, regardless if they execute correctly I believe.Binary log shows all non-failed queries. Nonetheless, the binary log is for internal use only ( maily to rebuild a db should there be a power failure o similar)
mhughes