0

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!

2 Answers2

1

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 127.0.0.1

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109
  • I think this is the right direction. Check the hosts file and see what's first on the line for 127.0.0.1 and use that. (It could be 'localhost.localhost') – Luke Aug 21 '09 at 03:59
0

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.

greg
  • 129
  • 6