PDOException: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (146) in lock_may_be_available() (line 167 of path/includes/lock.inc). -There is no error from log file, don't know why... tried replacing localhost which gave me [2002] error: PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' -credentials are also good... -same error message gets displayed in both cases when mysql is running & stopped. I tried everyother possibility obtained from google, but didnt work..
2 Answers
Literally everything was good. mysql was up and running. Checked by introducing bind-address in my.cnf to changing it back-and-forth from localhost to 127.0.0.1. The error got changed from SQLSTATE[HY000][2002] to SQLSTATE[HY000][2003] respectively. Nothing was working.I literally spent almost 10 hours to figure out this.
Solution: In my case, mysql.sock provides a tunnel between client and server mysql to interact. It only gets created when mysql server is up and running. My issue was the path where it was checking for the mysql.sock, didnt exist in that directory. So i had to create a symbolic link from that directory to the path where it actually existed. YES, it worked...
command to create a symbolic link
ln - s /path/where/it/actually/exists/mysql.sock /path/where/it/is/looking/for/mysql.sock
mysql
command? – Barmar