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.
In MySQL, the user accounts include the host you are connecting from. Hence,
root@localhost
and[email protected]
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.
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.)Here is the trick:
And then later:
Works fine.
There are two ways that I am aware of to log in to an account with an empty or blank password. The first is to just omit the password option.
Another way is to specify the
-p
option, and just hit the enter key when prompted.