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
Share on other sites

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);

?>

 

 

 

 

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.