Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Earlier I had a problem that had to do with .htacess files but I got that fixed but in the process I thought it would be good to re install Apache2. That fixed all web server problems, but when I tried to use MySQL, it gave me this error:

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

Please help :O. I'm ok with remaking all databases but I cant get MySQL to work, so I basically cant do anything with my server until this is fixed.

Thanks in advance :)

share|improve this question
1  
What does sudo service mysql status say? –  Marco Ceppi Mar 16 '12 at 14:40
    
Does that file exists? What are the permissions of it? Do this and post the result here: ls -l /var/run netstat -a | grep mysqld –  LnxSlck Mar 16 '12 at 15:00
    
It says 'mysql respawn/post-start, (post-start) process 8008' –  ccrama Mar 16 '12 at 15:07
    
LnxSlck I fixed the quote. That is what it says when I try to login... –  ccrama Mar 16 '12 at 15:08
    
Is apache running? –  LnxSlck Mar 16 '12 at 15:18
show 3 more comments

2 Answers

When I have that problem what I do is 3 things:

  1. Check if the mysql process is running. A ps -e should do the trick. For me, it did not work to do a service mysql stop. I had to manually killall mysql.

  2. Checked to make sure that the my.cnf was correctly pointing to where the the socket file should be. It sometimes happens that in a configuration you have /var/run... but then in the configuration file it says something else. Same thing for the place where the my.conf file should be. By default you see it in /etc/mysql/my.cnf but in other cases it might be in /etc/my.cnf (And the /etc/mysql folder should not be there to confuse with 2 mysql configuration sources)

  3. Lastly make sure that the directory where the socket file is has the correct permissions.

Most of the time 1 will suffice. It happens, at least for me when doing some configuration and I mistakenly reload mysql with a bad conf.

share|improve this answer
add comment

The error (2002) Can't connect to ... normally means that there is no MySQL server running on the system.y try restart

~$ sudo service mysql restart
mysql start/running, process 3912

or stop it and then start it

:~$ sudo service mysql stop
mysql stop/waiting

~$ sudo service mysql start
mysql start/running, process 3994

You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service. read more here.

Check whether the server is running on that host by executing sudo telnet some_host 3306 and pressing the Enter key a couple of times. (3306 is the default MySQL port number. Change the value if your server is listening to a different port.) If there is a MySQL server running and listening to the port, you should get a response that includes the server's version number. If you get an error such as telnet: Unable to connect to remote host: Connection refused, then there is no server running on the given port.

mine for example (in spanish):

~$ sudo netstat -a | grep mysql
tcp        0      0 localhost:mysql         *:*                     ESCUCHAR   
unix  2      [ ACC ]     FLUJO      ESCUCHANDO    18740    /var/run/mysqld/mysqd.sock

MINE IS WORKING: BUT LET SEE BY DOING A TELNET TO MY LOCALHOST. =D

~$ sudo telnet localhost 3306
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
E
5.1.61-0ubuntu0.11.10.1"]+Ya]-gQO{<X)_&<:NXConnection closed by foreign host.
marcelo@acer:~$ 

take a look at this: http://ubuntuforums.org/showthread.php?t=804021

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.