Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I create a new Mysql user, it is impossible to login using this user and password. Only if I crate a user without a password I can login.

For example:

mysql -u root -phererootpass
 grant all privileges on mydb.* to testuser@'%' identified by '' with grant option;
 grant all privileges on mydb.* to testuser2@'%' identified by 'mypass' with grant option;

mysql -u testuser  #<<< work fine

mysql -u testuser2 -pmypass  #<<< fail to login
ERROR 1045 (28000): Access denied for user 'testuser2'@'localhost' (using password: YES)

I'm using Mysql 5.0 on Red Hat v5

Please advice Mostar

share|improve this question
up vote 1 down vote accepted

What you've set up only allows you to connect from all other servers other than localhost. You need to run this as well

grant all privileges on mydb.* to testuser2@'localhost' identified by 'mypass' with grant option;

And then remember to flush your privs.

share|improve this answer
@mostar - you may want to visit You'll find that this topic is covered more there. – Patrick R Jan 6 '11 at 17:20
Thanks, that was the problem. – mostar Jan 7 '11 at 7:40

Try setting the environment variable MYSQL_PWD?

export MYSQL_PWD='mypass'
mysql -u testuser2 -p

In my experience passing the password as a part of the CLI is a bad idea. (it will show up in your process list for any user to see with 'top')

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.