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
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.
Now change the permission of .my.cnf file to either 400 or 600.
OR
Now
command will automatically log you in.
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();
)?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