PHP & Mysql socket error
published 8 July 2007
I keep coming across this whenever I set up MySQL and PHP on a new mac: mysql_connect() fails throwing an error …
mysql_connect() [function.mysql-connect]: Can't connect to local
MySQL server through socket '/var/mysql/mysql.sock'
And everytime I forget to remember what the solution was:
This can be fixed by changing settings in /etc/php.ini:
sudo cp /etc/php.ini.default /etc/php.ini
sudo vim /etc/php.ini
Then set the mysql default socket to the temp folder:
mysql.default_socket = /tmp/mysql.sock
Quite annoying, but then again: Hey, I’ve got a new Mac!!!
Comment
- Alternatively, you can also refer directly to the socket file in the call to mysql_connect (or in the configuration file of a CMS), replacing the host name ‘localhost’ with ’:/tmp/mysql.sock’ (note the leading colon). That’s my preferred method.
— Michel Fortin 8 July, 4:22am # - I ran into this problem. I set the server to 127.0.0.1 and it then it worked perfect.
— ernest leitch 8 July, 4:35am # - or just use the excellent MAMP, which doesn’t have any of these problems ;)
— tom 8 July, 3:15pm #
Quick links
Other people's articles that we think you might be interested in:
- Ajaxian » Web Inspector: Looking good, and profiling nicely
- smush it!
- cssdoc - Trac
- CSS Systems for writing maintainable CSS | Natalie Downe
- The PNG Gamma Dilemma - Trevor Morris Photographics
Want to buy a cheap laptop for your design work? read laptop reviews at laptopical.com