Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with
socket=/var/lib/mysql/mysql.sock
you can check if mysql is running with the following command:
mysqladmin -u root -p status
try changing your permission to mysql folder. If you are working locally, you can try:
sudo chmod -R 755 /var/lib/mysql/
that solved it for me
are you sure you installed mysql as well as mysql server..
For example to install mySql server I'll use yum or apt to install both mysql command line tool and the server:
yum -y install mysql mysql-server (or apt-get install mysql mysql-server)
Enable the MySQL service:
/sbin/chkconfig mysqld on
Start the MySQL server:
/sbin/service mysqld start
afterwards set the MySQL root password:
mysqladmin -u root password 'new-password' (with the quotes)
I hope it helps.
A quick workaround that worked for me: try using the local ip address (127.0.0.1) instead of 'localhost' in mysql_connect(). This "forces" php to connect through TCP/IP instead of a unix socket.