Welcome to WebmasterWorld Guest from

Forum Moderators: travelin cat

Message Too Old, No Replies

MySQL Login Via PHP - Won't Accept Same Login As phpMyAdmin

4:03 pm on Sep 13, 2012 (gmt 0)

New User

5+ Year Member

joined:Sept 13, 2012
posts: 3
votes: 0

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, 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.
5:46 pm on Sept 13, 2012 (gmt 0)

New User

5+ Year Member

joined:Sept 13, 2012
posts: 3
votes: 0

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!
6:29 pm on Sept 13, 2012 (gmt 0)

Moderator This Forum from US 

WebmasterWorld Administrator travelin_cat is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Feb 28, 2004
posts: 3238
votes: 12

JTeagle, Welcome to WebmasterWorld and thanks for coming back with the solution.
6:31 pm on Sept 13, 2012 (gmt 0)

New User

5+ Year Member

joined:Sept 13, 2012
posts: 3
votes: 0

Thanks for the welcome.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members