Mysql – Can’t use thesqld with empty password from command line

MySQL

First, I create a database directory:

$ mysql_install_db --datadir=./foo

Then, I start mysql daemon:

$ mysqld --port=5555 --datadir=./foo &

It starts fine and I can connect to it using, for example, Navicat. I'm trying to connect from shell:

$ mysql --user=root --port=5555 --password=
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

What to do? I also tried to change password first for root user:

$ mysqladmin -u root -P 5555 password foo
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

Again, connection works perfectly fine from a standalone SQL application, like Navicat.

Best Answer

In MySQL, the user accounts include the host you are connecting from. Hence, root@localhost and root@192.168.0.1 are different users and can have different passwords. Either of them can also not even exist.

Try this query and check whether your root users have different passwords.

SELECT user, host, password FROM mysql.user WHERE user = 'root';

If they do, log in using whatever method works and change the password of the root@localhost user to what you want it to be. (An empty string will be no password, however no password, especially for privileged users, is generally considered to be a bad idea.)

Related Topic