Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MySQL CLI doesn't require a password

Posted on 2013-02-03
4
Medium Priority
?
438 Views
Last Modified: 2013-02-20
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,
0
Comment
Question by:Frosty555
4 Comments
 
LVL 18

Accepted Solution

by:
Mark Gilbert earned 2000 total points
ID: 38849083
you will find that the root user has been granted * privileges with no password if you look at the permissions tab within phpmyadmin. This is a common setup for a lot of virtual hosts, so that the user that's able to log into the console automatically has access to edit every other setting and therefore gets root access to the database. The following page explains this, as well as how to button down your security:

http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38849227
The default installation for MySQL does Not set a password for 'root' as mentioned in that article.
0
 
LVL 80

Expert Comment

by:arnold
ID: 38849469
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.
0
 
LVL 24

Expert Comment

by:johanntagle
ID: 38850100
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question