I\'m learning PHP MYSQL and trying to create a database.
I\'m following this tutorial http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-f
There are two settings you have to check for this to work (assuming you have MySQL server installed of course):
Check the value of mysql.default_socket in your PHP configuration.
Check the value of socket in your MySQL configuration file under the [mysqld]
heading.
Those values have to be identical; if they're not, change one to match the other and restart respective service.
Apache servers use '127.0.0.1' instead of 'localhost'
This seems to be a common issue, as googling for it yields quite a few results. I experienced this on my two linux boxes as well (never under Windows though) and at some point I resolved to just use 127.0.0.1 on all dev servers. Basically, localhost makes the connection to the MySQL server use a socket, but your configuration doesn't point to the socket file correctly.
Here are a couple of resources that you might find useful:
http://westsworld.dk/blog/2011/03/problems-connecting-to-unixvarmysqlmysql-sock/ - basically what @Jack suggests, but more in depth
Can't connect to MySQL on Mac -- missing mysql.sock file - here's how to locate your socket file (for some reason, my php.ini had the path wrong, and I assume your case could be similar).
I hope this helps.