Correcting Warning: mysql_connect(): No such file or directory on OS X Yosemite 10.10.5

If you’re working on setting WordPress up on your OS X Yosemite 10.10.5 and continuously getting the “Cannot connect to database error” you are probably the victim of a bad socket in OS X.

If you have debugging enabled in your wp_config.php you may be presented with a ¬†warning like this: “Warning: mysql_connect(): No such file or directory”

You can correct this by creating a symlink to the mysql.sock file.

cd /var
sudo mkdir mysql;
sudo chmod 755 mysql;
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

That’s it! You should be able to run through the famous five minute installer now.