Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

mysql -uroot -p
Enter password:       <-- leave blank, hit enter without entering anything

mysql>                <-- i am logged in

NOTE: This is a new mysql instance installation

So if the password is blank, why won't it log me in without a -p flag?

For a little clarification. I am running into this issue when attempting to change the password using a script:

We're using a bash script to do that.

  • mysqladmin -u root password abc wouldn't work (access denied)
  • mysqladmin -u root -p password abc cannot be used because it prompts for a password and we need to automate this.
  • mysqladmin -u root -p'' password abc is not working either
share|improve this question
add comment

3 Answers 3

it's a default behavior for blank password.There is nothing wrong with it.

To allow yourself to log in to MySQL without having to type a password at the prompt, add your password to a file called .my.cnf in your home directory.

[client]
user=root
password=

Now change the permission of .my.cnf file to either 400 or 600.

chmod 400 .my.cnf

OR

chmod 600 .my.cnf

Now

mysql

command will automatically log you in.

share|improve this answer
    
Please beware about security implications for usernames with nonblank password. Nevermind for blank ones ;) –  kaji Jan 25 '12 at 7:06
    
The issue would show up when changing the password using mysqladmin, we're using a bash script to do that. mysqladmin -u root password abc wouldn't work (access denied) and mysqladmin -u root -p password abc cannot be used because it prompts for a password and we need to automate this. mysqladmin -u root -p'' password abc is not working either. –  gAMBOOKa Jan 25 '12 at 7:19
    
@gAMBOOKa myqladmin -u root password "abc" should work for blank password. Try with quotes –  kaji Jan 25 '12 at 7:41
    
Disregard the comment if you read it: It's not working... I was connected to incorrect server. So it's still not working... even with quotes - it's prompting for a password –  gAMBOOKa Jan 25 '12 at 7:54
1  
then something funny is going on with mysql. Are you running multiple instances mysql on same machine ??? When running multiple instances of mysql, client (eg mysql, mysqladmin) program gets confused as to which server the command is expected to execute for !! –  kaji Jan 25 '12 at 8:18
show 7 more comments

It's sending a password, despite not being given one; it's getting that from somewhere.

Check for a file at ~/.my.cnf.

But, set a password for your root user ASAP - unless you're perhaps being logged in anonymously (select current_user();)?

share|improve this answer
add comment

Because MySQL is set to use password auth, and if you don't provide the password on the command invocation (leaving it at "-p"), it would prompt you to then enter your MySQL password.

It may be easier to think of your password as being a carriage-return rather than being blank

share|improve this answer
add comment

Your Answer

 
discard

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.