Mysql - Access denied for user 'root'@'x.x.x.x' [duplicate]

I am trying to connect to a remote mysql database from my local box. Initially I was not even able to hit the mysql db. But after commenting the binding_address in the my.cnf file and restarting the mysql server, I am now able to hit it.

But now, I am getting an Access denied error

mysql -u root -h x.x.x.x -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'x.x.x.x' (using password: YES)

Is my IP being blacklisted or something? I can change that since I have admin permission on the remote box. Somebody help me.


Double check to make sure root has access from hosts/IPs other than localhost.

mysql> use mysql;
mysql> SELECT host FROM user WHERE user = 'root';

If it returns just one row with "localhost", you need to grant permissions to the IP you are connecting from.

mysql> GRANT SELECT, INSERT ON mydatabase.* TO 'root'@'10.0.0.1';

Replace mydatabase with the database you want access to (or put in a wildcard), then replace the IP with the address or subnet your client is connecting from.


First order of business is getting in with full permissions. If you cannot, add this line to your my.cnf and restart mysql:

skip-grant-tables

I recommend doing a little recon to see what users you have:

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

This will display your users list, something like:

mysql> SELECT user,host,password FROM mysql.user WHERE user = 'root' ORDER BY host ASC;
+------+------------+-------------------------------------------+
| user | host       | password                                  |
+------+------------+-------------------------------------------+
| root | 127.0.0.1  |                                           |
| root | ::1        |                                           |
| root | localhost  | *E0AD777475E6713F9B04317EE38888D61042DAC1 |
| root | randym-mbp |                                           |
+------+------------+-------------------------------------------+
4 rows in set (0.01 sec)

You need to see localhost in the list. If you do not, add it like this:

GRANT ALL PRIVILEGES ON *.* TO root@'localhost' IDENTIFIED BY 'your_password' WITH GRANT OPTION;

Otherwise simply update the password like this:

SET PASSWORD FOR root@'localhost' = PASSWORD('your_password');
FLUSH PRIVILEGES;

Then remove skip-grant-tables from your my.cnf and restart mysql.


Passwords in mysql are setup per IP. Usually they are only set for access via localhost only, especially for the root user. Verify that there is a root@% entry setup in your permissions table.

If you really do need to allow remote root access, then please consider changing the username so that people can't easily guess your servers superuser account.