How to get mysql.sock file, mistakenly deleted from "/mysql/tmp/"
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.
Solution 1:
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.