MySQL without password prompt

MySQLpasswordubuntu-12.04

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.

Best Answer

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.

Related Topic