Jump to content

mysql_connect() Access Denied error


limitphp

Recommended Posts

When I load the site on my local machine (using wamp server) I get this error:

 

( ! ) Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'testuser'@'localhost' (using password: YES) in C:\wamp\www\Greckle\inc_connGreckle.php on line 2

 

In the apache error log I get this:

 

PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'testuser'@'localhost' (using password: YES) in C:\\wamp\\www\\Greckle\\inc_connGreckle.php on line 2, referer: http://localhost/

[Mon Jul 30 19:21:11 2012] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://localhost/

[Mon Jul 30 19:21:11 2012] [error] [client 127.0.0.1] PHP  1. {main}() C:\\wamp\\www\\Greckle\\index.php:0, referer: http://localhost/

[Mon Jul 30 19:21:11 2012] [error] [client 127.0.0.1] PHP  2. include() C:\\wamp\\www\\Greckle\\index.php:4, referer: http://localhost/

[Mon Jul 30 19:21:11 2012] [error] [client 127.0.0.1] PHP  3. mysql_connect() C:\\wamp\\www\\Greckle\\inc_connGreckle.php:2, referer: http://localhost/

 

 

I setup the user testuser in phpmyadmin and added testdata database to his privileges and gave him full access.  Or at least i think I did.  I don't understand why its still saying access denied.

Link to comment
https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/
Share on other sites

Most likely a wrong username and/or password. Either that, or you haven't flushed the privileges after adding the user.

 

Can you post the exact method you used to create the user, and associated access? Sans any passwords, of course.

on phpmyadmin, on lefthand side I see list of all databases including testdata.  I click on users.  I clicked add user.  for username I put testuser.  For password, I put what matches in my code.  for "database for user" I left it at  none.

 

for global privileges I had it check all.  then I clicked the add user button.  then i went to "edit privileges" on testuser from the phpmyadmin.

 

under "Add privileges on the following database:" I clicked on testdata.  then under

Database-specific privileges for the testdata i clicked check all.  then i clicked the go button.

 

anyway, for the code to connect I have this:

 

 

<?php
$con = mysql_connect('localhost', 'testuser', 'xxxxxxxxx') or die ('Failed to connect to the database: '.mysql_error());
mysql_select_db ('testdata',$con);

?>

 

 

 

 

Good explanation, but..... why did you get different error messages ?

Open up phpmyadmin, go to sql tab (on the top), and copy/paste this code, post out the result:

SHOW GRANTS FOR 'root'@'localhost';

and 

SHOW GRANTS FOR 'testuser'@'localhost'

ok...I did it just for the user testuser and I got this error message:

 

#1141 - There is no such grant defined for user 'testuser' on host 'localhost'

 

 

here's a screenshot of the users.  on testuser, under hosts....there is a %.  Does that mean any host including localhost?

post-71319-13482403668235_thumb.png

Ok....I solved it.  I deleted the testuser and created it again.  This time I gave the user all access and localhost and set the testdata database privileges.  But, I think the problem was, I had to go back in the user privileges and set to all access to testdata.  I guess it had not done that last time, even though I set access to testdata.  Anyway, my issue is resolved. 

 

thanks all

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.