Link to home
Start Free TrialLog in
Avatar of Frosty555
Frosty555Flag for Canada

asked on

MySQL CLI doesn't require a password

I have a server where I can access MySQL via the command line interface by SSH-ing into the server as root, and then just typing "mysql". I get dropped to a MySQL command line interface.

In the mysql.user table, I do see the 'root'@'localhost' user but it has a password (the contents of the "password" field is filled with a hash).

I don't understand how I can login to the MySQL CLI without having to enter a password.

On my other server, we have to enter a password for root - and we happen to have set the root password in MySQL to the same password as is being used in SSH. I'd prefer it to work that way.

Can anybody point me at where this is configured?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Mark Gilbert
Mark Gilbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
The default installation for MySQL does Not set a password for 'root' as mentioned in that article.
There are multiple root entries and you empty password root attempt is accepted based on one of those
select * from mysql.user where user='root' and password='';
You could use
update mysql.user set password=Password('your password') where user='root';
flush privileges;

If you want to set the same password for all entries for root since root%127.0.0.1 and root%localhost and root%ipaddress are three separate entities.
Also take a look if you have a .my.cnf file in your root home directory.  It might have an entry like this:

[client]
password = something

Open in new window


Basically if you typed in just "mysql" it will check if you have an entry in the .my.cnf for user and/or password.  If you have an entry for user, it will use that as the user, otherwise it will use the your system account, which in this case, is root.  If you have an entry for password then it will use that too.  Note that you can put password only or user only in .my.cnf, though I recommend highly against it.  I think putting user credentials in the .my.cnf should only be acceptable on a personal machine which only you can access, and even that has security risks too.