Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
have you tried --password=''? – carillonator Jul 27 '12 at 14:03
yes, tried it - the same result – yegor256 Jul 27 '12 at 15:06

In MySQL, the user accounts include the host you are connecting from. Hence, root@localhost and root@ 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.)

share|improve this answer
I have to use empty password, it's an integration test scenario (difficult to explain the big picture). The problem is that I can't login with an empty password - yes, the user is there for the 'localhost' domain. – yegor256 Jul 27 '12 at 13:11
It's there but does it have a password and is the password different from the other root user? – Ladadadada Jul 27 '12 at 13:24

Here is the trick:

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

And then later:

$ mysql --socket=./sock --user=root --port=5555

Works fine.

share|improve this answer

Your Answer


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.