5

I was stuck with a PDO Exception

PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in lock_may_be_available() (line 167 of home/../includes/lock.inc).

In order to resolve that I tried to recreate the symbolic link using the command. I'm working on the Linux server.

 ln -s /home/../mysql/tmp/mysql.sock /tmp/mysql.sock

when executed the above sql statement, there was no change with the PDO exception. And later, I mistakenly deleted the mysql.sock file in "/home/../mysql/tmp/" (not in "/tmp").

How do I get back or re-create the mysql.sock file. Any idea regarding the PDO exception and how to resolve it.

7
  • restart MySQL (killall mysqld)
    – akuzminsky
    Aug 1, 2014 at 1:06
  • i restarted the server (server restart also restarts MYSQL right??) If so I didn't work
    – GIRI
    Aug 1, 2014 at 1:21
  • Remove the symlink, then restart MySQL.
    – ceejayoz
    Aug 1, 2014 at 1:24
  • so, do I need to redirect to the /mysql/tmp folder and remove the symlink??
    – GIRI
    Aug 1, 2014 at 1:27
  • I tried to do in both folders '/tmp' and '/mysql/tmp' using the cmd rm -d symlink shows the error "rm: illegal option --d usage: rm [-fiRr] file ..."
    – GIRI
    Aug 1, 2014 at 1:30

3 Answers 3

13
vi /etc/mysql/my.cnf

You will find the lines below top in your configuration file

[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

Make sure mysqld.sock is where it is supposed to be I don't like the path in your error message "/tmp/mysql.sock"

Since you are here look for this line as well

bind-address            = 127.0.0.1

If you are trying to connect from a remote location comment this line out.

Try to connect locally (from a terminal on the server)

mysql -u root -p

If security is not a concern for you (i.e it's your personal server not a multiuser environment) you can also make sure the file is readable by anyone

chmod a+r /var/run/mysqld/mysqld.sock

All the above should solve your connectivity issues. To get the file you could do a fresh installation of mysql server.

apt-get purge mysql-server
apt-get install mysql-server

Or you can download the mysql-server .deb package extract it and you should find it somewhere in there. Equivalently .rpm if you are using RHL.

Edit: Since you've been copying files around maybe the file ownership changed to root, check that also (with ls-la /path). Owner should be mysql group mysql. Can't think of anything else.

2
  • my problem was solved, below I gave my answer. But, I think your answer is more apt to my question. Thank you.
    – GIRI
    Aug 1, 2014 at 15:41
  • oh yeah. After so many hours spending to fix this. reinstalling the server worked like a charm
    – User123456
    Feb 26, 2020 at 8:57
0

I got this error after experimenting with the CHECK constraint in CREATE TABLE in MariaDB.

One of my experiments caused MariaDB to bail and tell me it couldn't reconnect to the server. Quitting and restarting led me to the Error 2002 message. As root, I issued a systemctl stop mysql command, and then I started mysqld manually with /usr/sbin/mysqld --skip-grant-tables --skip-networking.

Upon restarting the client, it connected to the server. I deleted the database that I was working on when the error occurred with a DROP DATABASE SQL command. I exited the client, killed mysqld and restarted it with systemctl start mysql. When I restarted the client, everything worked fine.

I recreated my database from a SQL dump and went back to work.

Luckily, I was working on a small database I was using to learn database management, and it didn't matter if I couldn't recover it.

-1

Got to change the configuration file httpd.conf root value

Previously,it was Listen : 0.0.0.0:80. I changed it to Listen: 0.0.0.0:8080 - changed the root to its higher value four digits (1024, 8008, 9999 etc) and restarted the apache server and mysql. Well, it worked.

And to My Question: mysql.sock file is a socket file it will be created automatically when the MySql server restarts

Finally, My issue is resolved.

1
  • mysql.sock file will be created automatically when mysql service restart as it is related with mysql service not apache service or server. Aug 12, 2015 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .