4

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").

Now, How do I get back or re-create the mysql.sock file. And anyidea regarding the PDO exception, how to resolve it.

  • restart MySQL (killall mysqld) – akuzminsky Aug 1 '14 at 1:06
  • i restarted the server (server restart also restarts MYSQL right??) If so I didn't work – GIRI Aug 1 '14 at 1:21
  • Remove the symlink, then restart MySQL. – ceejayoz Aug 1 '14 at 1:24
  • so, do I need to redirect to the /mysql/tmp folder and remove the symlink?? – GIRI Aug 1 '14 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 '14 at 1:30
11
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 1 '14 at 15:41
-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.

  • 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 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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