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.
Yes! First result for “mac mysql 127.0.0.1” – am starting a new job next week and can’t be messing about changing config files from localhost to 127.0.0.1 all the time – have been meaning to look at this for ages – ta!
This worked fantastically, I’ve been having to change database files all the time.
Thank You so much. I was very tired of “127.0.0.1” again, and again. My first thought was /etc/hosts/ but no…
This had been bothering me for ages but I’d never worked out why or how to fix it… Thanks for the solution!
Ay chihuahua! I have been looking for this solution for years. Finally I have found the grail. Now I can return to my fair lady and claim her as mine. : ) Thanks!
Another solution is to have a symlink
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Found there : http://www.coolestguidesontheplanet.com/downtown/get-apache-mysql-php-and-phpmyadmin-working-osx-109-mavericks
😉
@OVinz, thanks for your comment. I had to switch the order, and the socket path is different for mysql installed through MAMP:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Thanks for the tip! It worked like a charm.