How to see mysql error logs?

Solution 1:

Although I've managed to find them under /var/log/mysql/ (which is different from every source I was able to find),

Logfiles have been stored under /var/log/ for a long time now. It was changed to that location so they are added to "logrotate" by default. You can expect any log file in Ubuntu in /var/log/.

Secondly, under /var/log/mysql, there are files like error.log and error.log.1.gz error.log.2.gz.

The logs with numbers are older logs. Log files get compressed at some point by "logrotate". The settings for when it gets compressed are stored in /etc/logrotate.conf and by default files are compressed "weekly".

Except the error.log file, in order to read other files I have to extract them first. Is there any way, like some mysql command , to read them directly?

No you can't. And no that 1st part is not correct. 2 reasons:

  • The files ending in gz are at least a week old why would you need to see them? A week old errors are too old to be of any use.
  • You can view log files that are compressed.

    zcat /var/log/mysql/error.1.gz | more
    

    will show the lines of the file without uncompressing them.


And to add: log viewer also shows compressed log files. ALl you need to do is add the log file to the viewer (see "open" in the settings):

enter image description here