2

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.

  • 1
    have you tried --password=''? – carillonator Jul 27 '12 at 14:03
  • yes, tried it - the same result – yegor256 Jul 27 '12 at 15:06
0

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.)

  • 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
0

Here is the trick:

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

And then later:

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

Works fine.

0

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.

$ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 163714
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Another way is to specify the -p option, and just hit the enter key when prompted.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 163719
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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