Ubuntu – way to find out why MySQL crashed or quit working

MySQLUbuntu

I have MySQL running on an Ubuntu 12.04 web server. A basic LAMP stack.

I just have a couple of small websites running.

  • a WordPress site
  • A SugarCRM app
  • little apps here and there. Only 2 domains though

Today I made a new post on WordPress and checked back 30 minutes later to see an error…

Error establishing a database connection

I then checked my 2nd domain which has SugarCRM and saw an error there as well in regards to connecting to the database.

I then SSH'd into the server and ran service mysql restart

Checked my sites again and all was well!

So my question is, is there a way to find out what could of cause this to happen in some sort of log? Or any ideas?

Best Answer

Yes. MySQL has magical logs. For example:

  • The Error Log
  • The General Query Log
  • The Update Log
  • The Binary Log
  • The Slow Query Log
  • Server Log Maintenance

You'll need to check your my.cnf to see which logs are enabled and where they are located. You'll also need to check your version of MySQL to find out what configuration options exist for each log, and how to enable it if it's not already.

Once you do, you're just a less, grep, and maybe a sed or two away from finding what took your server down.