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.


6 Answers 6


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'@'';

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.

  • yeah.. i only have localhost there. How do i grant permission to the IP ?
    – bragboy
    Jan 31, 2011 at 22:57
  • mysql> GRANT SELECT, INSERT ON mydatabase.* TO 'root'@'';
    – Serge Stepanov
    Jan 31, 2011 at 22:58
  • 2
    Also don't forget to flush privileges. mysql> FLUSH PRIVILEGES;
    – Serge Stepanov
    Jan 31, 2011 at 22:59
  • Do i need to restart the server after doing this ?
    – bragboy
    Jan 31, 2011 at 23:03
  • 3
    @Bragboy you probably need to set a password for the account too rather than just leave the account passwordless. By default, each grant entry has a separate password too. Look up the GRANT command in the mysql docs, I forget the exact clause now (I usually manage users with phpmyadmin) Feb 1, 2011 at 0:53

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


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 |  |                                           |
| 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:


Otherwise simply update the password like this:

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

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

  • Thanks for the answer. However, I needed to use double quotes to set password. SET PASSWORD FOR root@'localhost' = PASSWORD("password");
    – cell-in
    Sep 2, 2018 at 8:18

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.


For Unix like systems the following solution worked for me to reset the root password: http://www.cyberciti.biz/tips/recover-mysql-root-password.html


Recover MySQL database server password with following five easy steps:

  1. Stop the MySQL server process.

  2. Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.

  3. Connect to mysql server as the root user.

  4. Setup new mysql root account password i.e. reset mysql password.

  5. Exit and restart the MySQL server.

Specific commands: (login as the root user):

  1. Stop mysql service

    # /etc/init.d/mysql stop


    Stopping MySQL database server: mysqld.
  2. Start to MySQL server w/o password:

    use mysqld_safe:

    mysqld_safe --skip-grant-tables &


    [1] 5988
    Starting mysqld daemon with databases from /var/lib/mysql
    mysqld_safe[6025]: started
  3. Connect to mysql server using mysql client:

    # mysql -u root


    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  4. Setup new MySQL root user password

    mysql> use mysql;
    mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
    mysql> flush privileges;
    mysql> quit
  5. Stop MySQL Server:

    # /etc/init.d/mysql stop


    Stopping MySQL database server: mysqld
    STOPPING server from pid file /var/run/mysqld/mysqld.pid
    mysqld_safe[6186]: ended
    [1]+  Done                    mysqld_safe --skip-grant-tables
  6. Start MySQL server and test it:

    # /etc/init.d/mysql start
    # mysql -u root -p

Its possible that you need to grant privileges for that IP, an example would be:

mysql> GRANT ALL PRIVILEGES on dbname.* to root@'%'; mysql> FLUSH PRIVILEGES;

grants to all IPs


Unfortunately mysql permissions distinguish by host and ip. Permissions granted for a hostname do not work for an IP and vice versa.

Make sure you grant permissions for the user and host ip/host name you are connecting from.

  • This is definitely not unfortunate. Personally, I don't want the root user, or a couple other users able to be logged into remotely, but I might like to allow some other users with limited permissions to connect remotely. Jan 31, 2011 at 23:01
  • 3
    Permissions are checked by ip and FQDN separately. If i connect from my box and the mysql server is able to resolve my ip into a FQDN then the rules differ from the situation where my ip is not resolvable. I'd call this inconsistency unfortunate.
    – Spliffster
    Jan 31, 2011 at 23:08

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