For a long while now I’ve been connecting to MySQL on my development platform with 127.0.0.1 because for some reason localhost didn’t work.
Turns out it’s because 127.0.0.1 uses TCP/IP and localhost uses sockets.
The php.ini file points to the wrong place for the mysql.sock so all you have to do is change it, restart apache and voila!
- Open php.ini: /private/etc/php.ini
- Find the following line: mysql.default_socket = /var/mysql/mysql.sock
- Replace with: mysql.default_socket = /tmp/mysql.sock
- Restart apache: apachectl restart
- Happy days!
Note: If you don’t have a php.ini file, you need to copy the provided default called php.ini.default
sudo cp /private/etc/php.ini.default /private/etc/php.ini
Thanks to Blog.Andrei.MD for the info.