Solved

MySQL CLI doesn't require a password

Posted on 2013-02-03
4
419 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:
ingwa earned 500 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 83

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 77

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now