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.

Dave M
  • 4,494
  • 21
  • 30
  • 30
GIRI
  • 151
  • 1
  • 1
  • 5

3 Answers3

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.

  • my problem was solved, below I gave my answer. But, I think your answer is more apt to my question. Thank you. – GIRI Aug 01 '14 at 15:41
  • oh yeah. After so many hours spending to fix this. reinstalling the server worked like a charm – User123456 Feb 26 '20 at 08: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.

mforsetti
  • 2,488
  • 2
  • 14
  • 20
-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.

GIRI
  • 151
  • 1
  • 1
  • 5
  • mysql.sock file will be created automatically when mysql service restart as it is related with mysql service not apache service or server. – Zafar Malik Aug 12 '15 at 09:02