Wednesday, February 13, 2008

Woops! MySql didn't start when the server rebooted!

One of my customers had this problem today. I got a text message, "Lisha! Can you look at the server and tell me why mysql isn't working? I rebooted the server and now the website has an error. Something about Error #2002 and the mysql.socket."

It turned out that when they rebooted their LAMP server, the mysql demon didn't turn on with the rest of the services like the apache http demon. Luckily, this is easy to fix. I ssh'd to their server and got to work.

First, I checked to see if my hunch was right:
mysqladmin ping
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!

Yipes! Yup, you have no bananas (or mysql, as the case my be).

Next, I ran the mysql initialization script:
/etc/init.d/mysqld start
Starting MySQL: [ OK ]

Then check to see if it worked:
mysqladmin ping
mysqld is alive

Ah, yes. All better!

Next time, we can make mysql demon startup at boot time. On a Red Hat type system you can run the following code as root (or via sudo) to run the initialization script automatically at boot:
ln -s /etc/rc.d/init.d/mysqld /etc/rc.d/rc3.d/S98mysql

No comments: