limitphp Posted July 31, 2012 Share Posted July 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/ Share on other sites More sharing options...
Christian F. Posted July 31, 2012 Share Posted July 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365575 Share on other sites More sharing options...
hakimserwa Posted July 31, 2012 Share Posted July 31, 2012 can you post the code for creating this function Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365603 Share on other sites More sharing options...
limitphp Posted August 1, 2012 Author Share Posted August 1, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365845 Share on other sites More sharing options...
jazzman1 Posted August 1, 2012 Share Posted August 1, 2012 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' Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365849 Share on other sites More sharing options...
limitphp Posted August 1, 2012 Author Share Posted August 1, 2012 ok, I opened up phpmyadmin and put that code in the sql tab. I got this: Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365857 Share on other sites More sharing options...
limitphp Posted August 1, 2012 Author Share Posted August 1, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365859 Share on other sites More sharing options...
jazzman1 Posted August 1, 2012 Share Posted August 1, 2012 Delete all users from database, if you don't need it. Keep only "root localhost ..... ", and replace "testuser % " with " testuser localhost" or "testuser 127.0.0.1". Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365866 Share on other sites More sharing options...
Christian F. Posted August 1, 2012 Share Posted August 1, 2012 Did you flush the privileges after granting access to the user? If not, then you need to do so, otherwise MySQL will not load the new user data into memory and thus not know of its existence. Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365882 Share on other sites More sharing options...
limitphp Posted August 1, 2012 Author Share Posted August 1, 2012 ok, i'll replace testuser % with testuser localhost. how do you flush privileges? Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365888 Share on other sites More sharing options...
Christian F. Posted August 1, 2012 Share Posted August 1, 2012 FLUSH PRIVILEGES;..... You could very easily have Googled that, you know... "flush privileges mysql" was all that was needed. Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1365893 Share on other sites More sharing options...
hakimserwa Posted August 1, 2012 Share Posted August 1, 2012 ok, i'll replace testuser % with testuser localhost. how do you flush privileges? http://dev.mysql.com/doc/refman/5.0/en/flush.html Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1366035 Share on other sites More sharing options...
limitphp Posted August 1, 2012 Author Share Posted August 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266477-mysql_connect-access-denied-error/#findComment-1366075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.