Solved

MySQL CLI doesn't require a password

Posted on 2013-02-03
4
418 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 82

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 76

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

757 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

21 Experts available now in Live!

Get 1:1 Help Now