Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have access to shared university research server that I want to host a php/mysql site on. I've compiled and run the mysql server and can connect to it fine using the 'mysql -u -h localhost -p', however when I use the exact same credentials and parameters through a PHP script, I always get 'access denied for user@localhost'. I did some more digging and found that even when my instance of the server isn't running, I get the same error message, which suggests there is an issue with the fact that this server is shared and running possibly multiple instances of mysqld. I've tried altering the port and socket and connecting to them explicitly through the script, but still have no had any luck. My PHP code works fine locally, so there's nothing syntactically wrong as far as I can tell.

Has anyone experienced a similar problem or can perhaps point me in the direction of some resources? Thanks in advance for your time!

share|improve this question
I think that this is a duplicate of this question… – Dana the Sane Aug 21 '09 at 1:09
Similar question but possibly a different cause. – John Gardeniers Aug 21 '09 at 3:12

I've had this before. It turned out to be a problem with localhost not resolving properly or reliably. See what happens if you replace that with

share|improve this answer
I think this is the right direction. Check the hosts file and see what's first on the line for and use that. (It could be 'localhost.localhost') – Luke Aug 21 '09 at 3:59

I just had a similar issue but I'm connecting to MySQL on a different machine. I solved my issue by passing a hostname (I created in /etc/hosts) to mysqli connect instead of an IP address. Not sure why that resolved it, but it did.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.