ERROR 1045 (28000): Access denied for user (using password: YES)

Licia picture Licia · Nov 18, 2016 · Viewed 36.5k times · Source

I am trying to have a simple mysql Database on a server and another database on another server that connects to it.

I have done the following :

  1. Installed mysql-server
  2. Created the database
  3. Created the user with :

    CREATE USER admin@'localhost' IDENTIFIED BY 'admin';

  4. Given the privileges to this user with :

    GRANT ALL PRIVILEGES ON confWeb.* TO admin@'';

  5. Opened the bind-adress

Now when I launch the command mysql -u admin -p -h <address> from another server, it just tells me again and again :

ERROR 1045 (28000): Access denied for user 'admin'@'X.X.X.X' (using password: YES)

I really have no idea what to do at this point. I think I've tried everything. I tried putting GRANT OPTION in the end of the GRANT line, I tried allowing a lot of different addresses but nothing worked.

Answer

spencer7593 picture spencer7593 · Nov 18, 2016

In MySQL, a user is identified by both user and host.

This user:

 admin@localhost

is not the same user as

 admin@'10.242.167.235'

As one option, you could do this to allow connection:

  GRANT USAGE ON *.* TO admin@'10.242.167.235' IDENTIFIED BY 'mysecret' ;
  GRANT ALL ON confWeb.* TO admin@'10.242.167.235' ;

For a longer discussion of the MySQL Access Privilege System, including "wildcards", the special meaning of localhost, using IP addresses instead of hostnames, etc.

http://dev.mysql.com/doc/refman/5.7/en/privilege-system.html