|MySQL Login Via PHP - Won't Accept Same Login As phpMyAdmin|
I'm pretty much a Mac newbie (and not exactly comfortable with MySQL administration), so be gentle with me.
I've got what I believe is a pretty standard installation of MySQL running on my MacBook, and the MySQL database has some tables and users. In and of itself, I know this is working (see below).
I have my main machine, which is Windows, and I'm trying to develop PHP by using the Mac as my server.
If I run up phpMyAdmin (whose files are located on the Mac) and log in using root and the password I set, it works; I get access and I can administer the databases.
If I try and connect in using PHP's mysql_connect (via the client machine's web browser), using the same credentials and either localhost:3306 or 127.0.0.1:3306, it refuses, saying 'Access denied for user 'root'@'localhost' (no, I'm *not* accidentally passing the single quotes in!).
Just for the sake of it, I tried the same PHP page directly on the Mac... and it failed in exactly the same way. The same Mac that lets me in with phpMyAdmin!
Am I missing something? Any help would be appreciated.
* phpinfo() reports that mysql.default_socket is set to /tmp/mysql.sock - I can confirm that that file does indeed exist on the Mac and the info panel says everyone has read / write access to it. It also confirms that MySQL support is enabled.
OK, I have figured out what I was missing.
I decided not to give up, and went into phpMyAdmin and created a brand new user with password, all privileges. I then used this username / password combo in the PHP, and lo and behold, it worked.
So I went back to the Privileges page to see if I could spot a difference... and finally I saw what I should have seen in the first place: none of the other logins required a password. The problem was, I had not seen this before and phpMyAdmin doesn't allow a login without a password. Not only did it accept the password I had apparently set, but it also *required* it. I'm guessing that password was purely for phpMyAdmin's benefit, and it only passed the username you used on to MySQL.
A little bit irritating to have that discrepancy between phpMyAdmin's login and what was required for MySQL, but that will teach me not to look at the users I had set up.
Hopefully my gaffe will help someone else who is falling into the same trap - ignore the password phpMyAdmin uses and check the Privileges page yourself!
JTeagle, Welcome to WebmasterWorld and thanks for coming back with the solution.
Thanks for the welcome.