MySQL Can’t connect to /var/lib/mysql/mysql.sock
If your running a local MySQL installation, the mysql client will attempt to connect through a socket file. The default location of the socket file is typically /tmp/mysql.sock or /var/lib/mysql/mysql.sock. If you are doing a custom install (eg. building from src) you may need to modify this location to suit your needs.
You can verify if this is your problem by attempting to connect to the specific socket when starting the mysql client.
mysql -S/var/lib/mysql/mysql.sock ...
Typically MySQL configuration is done in /etc/my.cnf. Here you can define the location of your datadir, sock… etc files as required. For an installation in /opt/mysql.. your my.cnf file may look something like:
[mysqld] basedir=/opt/mysql datadir=/opt/mysql/data socket=/opt/mysql/mysql.sock [client] socket=/opt/mysql/mysql.sock [mysql.server] basedir=/opt/mysql [mysqld_safe] err-log=/opt/log/mysqld.log
It is important to note you must define the proper location of the socket file for both the [client] and [mysqld] sections as they function independantly.
If your are only having problems when hitting PHP web pages that are locally hosted, you can modify the /etc/php.ini file to define your default socks file as follows:
; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. mysql.default_socket = /opt/mysql/mysql.sock