Solved

MySQL CLI doesn't require a password

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (https://kb.isc.org/article/AA-01272), affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

820 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