Question

I have been using the LAMP stack on a Ubuntu setup.

It has been working fine, set up multiple databases everything is going fine, and then suddenly this morning I started getting database errors from the webpage I was using, then trying to access PHPMyAdmin got:

error #2002 Cannot log in to the MySQL server

I go into the bash prompt and try to log-in as the root user see whats up I get a similar error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 

I checked that the mysql.sock file existed which it does, in the specified path in the error above. Permissions where all good, and owned by mysql. I reset the permissions just in case and still get the same error.

Here is the file as seen from BASH:

srwxrwxrwx 1 mysql mysql 0 Oct 21 05:10 mysqld.sock

I thought I would just restart the service, but get the same error when trying to stop, start or restart the service.

This really baffled me, I am no expert with linux or anything, but don't understand how this can suddenly happen when I didn't change any of the config settings, and it was running perfectly fine for the last few months.

I tried restarting Apache, and got the error:

apache2: bad user name ${APACHE_RUN_USER}

I don't think that is related to the MySQL stuff but thought it could be involved. The Apache error seems to more be with the set-up but knowing my luck being lazy has caused my to overlook simple things that has caused it all to come crashing down.

Any help on how to fix the problem, and more importantly prevent this occurrence the future would be greatly appreciated.

I have tried most things that were returned by a basic Google search, and a look around here. I have not yet tried deleting and recreating the sock file, but most other things so far have not worked.

EDIT:

I just wanted to add that the Apache server is still running fine, nothing wrong there even though I do get the error when trying to stop and restart it. Pages that don't rely on MySQL still load without issue.

I have also tried killing mysql processes through searching the PIDs and also as suggested below killall mysqld (and also killall mysql just for kicks). No processes found through these attempts.

I don't know if it is relevant or not, but I can't open (in vim) or view the mysqld.sock file (permission denied) even when using the superuser.

Was it helpful?

Solution

Have you tried using

killall mysqld

to kill the server instead of just ending the service, and then starting the MySQL service?

Or you could try deleting mysql.sock using

rm /var/run/mysqld/mysqld.sock

Then you would just need to run the MySQL server again by either starting the service or running

mysqld

It should create a new /var/run/mysqld/mysqld.sock for itself and all should go well. Just a thought: this may have happened because the computer wasn't powered-off correctly, or perhaps MySQL just got a bit confused.

OTHER TIPS

Create one micro instance swap space in Ubuntu

dd if=/dev/zero of=/swapfile bs=1M count=1024

mkswap /swapfile

swapon /swapfile

did you try to just restart the mysql server

/etc/init.d/mysqld restart 
/etc/init.d/mysqld stop 
/etc/init.d/mysqld start
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top