By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

Access denied for user: username@%

P: n/a
red
I know this is probably a faq but it is hard to search for this exact
problem.
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
AUTO_INCREMENT ,'
. ' masterid mediumint( 8 ) unsigned NOT NULL default \'0\','
. ' filedata blob NOT NULL ,'
. ' PRIMARY KEY ( id ) ,'
. ' KEY master_idx( masterid ) ) TYPE = MYISAM ';
mysql_query($sql);
db(mysql_error());
?>
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
'@%' ?

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
red
red wrote:
I know this is probably a faq but it is hard to search for this exact
problem.
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
AUTO_INCREMENT ,'
. ' masterid mediumint( 8 ) unsigned NOT NULL default \'0\','
. ' filedata blob NOT NULL ,'
. ' PRIMARY KEY ( id ) ,'
. ' KEY master_idx( masterid ) ) TYPE = MYISAM ';
mysql_query($sql);
db(mysql_error());
?>
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
'@%' ?

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
debate.
Jul 17 '05 #2

P: n/a
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.

Regards,
Deon H
Jul 17 '05 #3

P: n/a
red
Deon H wrote:
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.

Regards,
Deon H

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
mysql
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
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.