views:

69

answers:

4

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dbuser1'@'localhost

This is probably something stupid, but I created some code to access my database from a PHP script but there was an error (dbuser1 doesn't exist) at the first run and now its stuck with the same error even if I change the username to another one. I've even renamed the PHP file, uploaded it, and ran the new file with different name and the error is the same (still showing old name dbuser1 instead of dbuser1000). I'm new to web development so maybe I'm just misunderstanding something. I'm using Bluehost shared.

+2  A: 

You need to ensure you have created the relevant MySQL user.

Without posting your code that's about all the help I think we can be.

Michael Robinson
+1  A: 

You have to grant access permissions in MySQL to the username you're using within your PHP code

If your PHP code looks something like this:

$db_server = 'localhost';
$db_user = 'dbuser1';
$db_passwd = 'guessme';

$con = mysql_connect($db_server, $db_user, $db_passwd);

Then you'd have to do the following in MySQL to grant permissions to this account:

GRANT list,of,permissions ON databasbase.table TO dbuser1@localhost IDENTIFIED BY 'guessme';

If you're connecting to a remote MySQL instance, then you have to grant permissions to the host you're connecting the PHP script from, etc... Full details are on the linked MySQL doc page above.

Marc B
For full permissions, the statement would be:GRANT all ON *.* TO 'dbuser1'@'localhost' IDENTIFIED BY 'guessme';I also added single quotes around the user and machine. MySQL generally likes that I believe.
TheJacobTaylor
I never grant 'all' on an account that's being used by a web service I've coded. Minimum permissions, always. I hate having to grant 'all' on a wordpress/drupal setup. Seems... dirty.
Marc B
A: 

Check your password!

Joey Ezekiel
A: 

ok here is solution for your problem :-
1) check/match the link of your if it is right.
2) if problem still exits than do as i say :-
search by using "find" / ctrl+f on your editor and search in folder of the project where is the name "dbuser1" u have written and now goto that place and check password and your localhost,
some times it happens that we consider localhost as our server but actually it is "127.0.0.1"
so please be careful at such logical mistakes.
Make sure that your USER has proper rights to ACCESS the database :)

for more u have to paste ur sample code

hope this helps , or u need to give some sample code , or

Extjs Commander