4

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.

elzaer
  • 729
  • 7
  • 25
  • What error exactly did `service mysql restart` give? What about `service mysql status`? Is there anything showing in the messages log? (Sorry, I'm more familiar with SUSE so that's `/var/log/messages` for me) – Basic Nov 04 '12 at 02:27
  • Have you tried, you know, reading the error logs to discover what it's trying to tell you? – Gavin Towey Nov 04 '12 at 02:31
  • mysqld restart (and other variations) gave the same mysql.sock error. As detailed below I ended up deleting and launching the service again and it seemed to do the trick. Should of really tried this first up. I didn't check the error log but am going to look into it now – elzaer Nov 04 '12 at 03:05

3 Answers3

5

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.

phillid
  • 198
  • 1
  • 11
  • I did try this and came up with: no processes found. I should add I had a look through the PID list to try and kill anything lingering there but nothing was there – elzaer Nov 04 '12 at 02:32
  • I added this to the original question as it seemed fairly relevant that this didn't work for me. – elzaer Nov 04 '12 at 02:35
  • 1
    Okay. How about rm'ing mysql.sock and executing the server directly from the command line ('/etc/mysqld/mysqld' I think) to capture any info and errors as they occur. mysqld should re-create the socket file. – phillid Nov 04 '12 at 02:42
  • That seemed to do the trick, do you want to add this to your answer and I will check it off? – elzaer Nov 04 '12 at 03:01
2

Create one micro instance swap space in Ubuntu

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

mkswap /swapfile

swapon /swapfile

Community
  • 1
  • 1
Bhawna
  • 15
  • 2
1

did you try to just restart the mysql server

/etc/init.d/mysqld restart 
/etc/init.d/mysqld stop 
/etc/init.d/mysqld start
hish
  • 145
  • 4