Access denied for user: username@%

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I know this is probably a faq but it is hard to search for this exact
When I put this on a php page:
$link = mysql_connect("localhost", "cardini", "password")
    or die("Could not connect : " . mysql_error());
echo "Connected successfully\n";
mysql_select_db("articles") or die("Could not select database");

   $sql = 'CREATE TABLE image( id mediumint( 8 ) unsigned NOT NULL
         . ' masterid mediumint( 8 ) unsigned NOT NULL default \'0\','
         . ' filedata blob NOT NULL ,'
         . ' PRIMARY KEY ( id ) ,'
         . ' KEY master_idx( masterid ) ) TYPE = MYISAM ';
This is the result:
Connected successfully

[Access denied for user: 'cardini@%' to database 'articles']

How can it connect successfully to the database, yet with the same user
and password, fail to connect ?

or maybe a better question would be: How did 'localhost' get changed to
'@%' ?

Re: Access denied for user: username@%

red wrote:

Quoted text here. Click to load it
I figured out what that cryptic messge meant- the user had not been
granted the appropriate privilege, in this case the create privilage.
I was in the middle of granting privilages when I got distracted by the

Re: Access denied for user: username@%

Hi there, Red.
Will you please be so kind as to help me out with your solution - I have
the same problem and I am totally new to this.

Deon H

Re: Access denied for user: username@%

Deon H wrote:
Quoted text here. Click to load it
The problem confused me because my username and password successfully
connected to the database but didn't work when I tried to create a
table. But this does make sense because to create a table you not only
have to have a username and password to connect to the database, you
must have the right to create a table within that database.

I'm using windowsxp, this is how I grant rights:

1)Go to the command prompt. There is a link in the start menu.
2)Change the directory to the directory of mysql. The letters cd are     
used to change the directory. On my computer, I write:
cd c:\mysql\bin
The prompt changes to c:\mysql\bin>
3)logon to the root account of mysql . If your mysql is set up properly,
simply typing
without a username and password should give you an access denied
message. If it lets you in without giving you an access denied message,
then you still have a default user which should be deleted.

To access the root account type mysql -u root -p
It will then ask you for your root password and let you in

4) To grant rights, use the grant command. If I want to grant
"myusername"  with a password of "mypassword" the rights that most users
are allowed to have to "mydatabase" I would use:

grant select, insert, update, delete, index, alter, create, drop on
mydatabase.* to myusername identified by 'mypassword';

Notice the single quotes around the password. Those are the only quotes
in the whole command.

That fixed the problem for me

Site Timeline