Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a MySQL server with the MySQL root password is an empty string. If I try to connect to MySQL without a password, I am denied. Like this:

# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
# mysql -p
Enter password:   <-- I just hit enter, without typing anything
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql>

How can I get MySQL to let me connect without prompting me for the password first? I have other servers where I can connect just fine without prompting for any password, and those other servers aren't using a .my.cnf file either.

share|improve this question
    
What's output from select user, host, password from mysql.user;? –  Shane Madden Sep 9 '13 at 19:36
    
It's the same on both computers. This computer forces me to use the password prompt: +------+-----------+----------+ | User | Host | Password | +------+-----------+----------+ | root | localhost | | | root | server2 | | | root | 127.0.0.1 | | | root | ::1 | | This computer doesn't prompt me: | User | Host | Password | +------+-----------+----------+ | root | localhost | | | root | server1 | | | root | 127.0.0.1 | | | root | ::1 | | –  ricksebak Sep 9 '13 at 19:38
1  
is there actually a value for the password field in mysql.user? –  USD Matt Sep 9 '13 at 19:39
    
That formatted terribly, but the password field is blank on the server that prompts me for a password and blank on the server that doesn't prompt me. –  ricksebak Sep 9 '13 at 19:41
    
Is there some shell alias or override set for the mysql command? If you don't specify the -p option, it should not say 'using password: yes' –  USD Matt Sep 9 '13 at 19:43

2 Answers 2

up vote 1 down vote accepted

Not that I would encourage running MySQL without a password if you're storing anything of value, but in this case the problem seemed to be a shell alias for the mysql command which was specifying user/password options.

Usually if you just run 'mysql', you'll get an error along the lines of 'access denied (using password: NO)'. At this point you'd realise that you need to tell mysql to ask you for the password by using the -p option. (Or specify the password directly in the command with --password=pass).

In this question the clue was that the error suggested a password was being used, even though no password options have been provided on the command line directly. If mysql has no password, any supplied password (even blank) will cause an auth failure.

share|improve this answer

Is a segurity risk but, if you add this to your my.cnf:

skip-grant-tables

You can access to mysql whitout password.

Is better create a /root/.my.cnf file for access whitout password prompt

share|improve this answer
    
Why was that downvoted? If this a security flaw, it should be fixed in mysql. –  ott-- Sep 9 '13 at 20:31
    
@ott--, this isn't a security flaw. It is a feature designed for repairing a server when authentication is broken. It doesn't really address the original question. –  Zoredache Sep 9 '13 at 20:55
    
Not is a bug yes, is a feature but if you add it is a segurity risk for your server, and also is valid to access mysql whitout password, I use it for my local enviroment, but of curse not for production servers. And maybe not respond the questions because my english is bad, and I dont understand somethings, but I try to improve my english and try to help :/ –  Skamasle Sep 13 '13 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.