Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a new user with password

Status
Not open for further replies.

nsr250

Programmer
Mar 26, 2004
3
CA
Hi,

I tried to add the following user as root:

mysql> GRANT ALL ON testDB.* TO forum@'%' IDENTIFIED BY "password";

However, how come I cannot connect to testDB using my new user with a password? But without typing password, the connection is successful?

C:\mysql\bin>mysql -u forum -ppassword testDB
ERROR 1045: Access denied for user: 'forum@localhost' (Using password: YES)

C:\mysql\bin>mysql -u forum
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29 to server version: 4.0.15-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
 
mysql> GRANT ALL ON testDB.* TO forum@'%' IDENTIFIED BY "password";

I'm not sure, but try just using single quotes around the password.

I don't think MySQL treats doubles and singles the same.


[cheers]
Cheers!
Laura
 
the mysql manual has this syntax

Code:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

indicating the username should be in single quotes as well. im spoiled by mysql manager software, so im not sure myself.
 
I'm still trying to get the hang of user management on MySQL, but I think your Grant statement should have been:
[tt] GRANT ALL ON testDB.* TO
forum@'%' IDENTIFIED BY 'password',
forum@localhost IDENTIFIED BY 'password'
[/tt]
assuming your MySQL server is located on the machine you were using.

Since forum@localhost was not in the user list, the server looked up the user ''@localhost, saw that it uses no password, and so rejected your login. When you omitted the password, it accepted your login as ''@localhost.

It's not a matter of quotes; MYSQL always allows the choice of single or double quotes, and the components of an account name (the bits before and after the @) only need be enclosed in quotes if they contain special characters.

Maybe somebody more knowledgeable about user management will correct me if I'm wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top