MySQL error: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
There are a lot of possible solutions online, but I will tell you about the one that worked for me.
Some weeks ago I was setting up a Red Hat Linux Web Server and installing Apache, PHP and MySQL. I do not know what I did wrong, if I did anything wrong, but I wasn’t able to start the MySQL daemon.
I would get the following error message in the browser when trying to connect with PHP…
Warning: mysql_connect() [function.mysql-connect]:
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) in /usr/local/apache2/htdocs/connect.php
on line 10
Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
I would get a similar error when I would try to connect through the Linux terminal.
Now, I’m no Unix guru. I have barely read a Sams Teach Yourself Red Hat Linux book and gotten to about chapter 5. As of the time of this writing I just know basic Unix skills. It’s one of my goals to study Linux throughly and hopefully will find the answer as to WHY I couldn’t start MySQL. For now, I will just tell you how I fix it.
I searched the internet hoping to quickly find an answer to my problem as it usually happens. Apparently, this error relates to having more than one MySQL installation. I found many different “solutions” to the error message but none worked on this system. It took me several days of trying different possible solutions at a north pole cold computer room. (I live in Texas, so for me it feels like I’m about to get frostbite.)
Until I found instructions to run this command…
# killall -9 mysqld
Outputs…
mysqld: no process killed
[/usr/local/mysql/bin:0]
Then I tried to start the MySQL daemon by running…
# ./mysqld –u root -p
Outputs…
080604 18:19:14 InnoDB: Started; log sequence number
0 4631503
./mysqld: ready for connections.
Version: ‘4.1.22-standard-log’ socket:
‘/tmp/mysql.sock’ port: 3307 MySQL Community Edition
- Standard (GPL)
And it worked! Wohooo! I felt sooooo relieved.
I just thought I would share the answer with you in case any of you run into the same problem and can’t find how to fix it. Hope I saved you hours of headache.
Tags: MySQL, Troubleshooting