Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user


MySQL 5.1.31 running on Windows XP.

From the local MySQL server ( I can connect as root as follows:

>mysql --host= --user=root --password=redacted

From a remote machine (, I can see that the mysql port is open:

# telnet 3306
Connected to (

But when trying to connect to mysql from the remote machine, I receive:

# mysql --host= --user=root --password=redacted
ERROR 1045 (28000): Access denied for user 'root'@'' (using password: YES)

I have only 2 entries in mysql.user:

Host         User     Password
localhost    root     *blahblahblah
%            root     [same as above]

What more do I need to do to enable remote access?


As suggested by Paulo below, I tried replacing the mysql.user entry for % with an IP specific entry, so my user table now looks like this:

Host             User     Password
localhost        root     *blahblahblah  root     [same as above]

I then restarted the machine, but the problem persists.

1/16/2016 2:00:50 AM

Accepted Answer

Paulo's help lead me to the solution. It was a combination of the following:

  • the password contained a dollar sign
  • I was trying to connect from a Linux shell

The bash shell treats the dollar sign as a special character for expansion to an environment variable, so we need to escape it with a backslash. Incidentally, we don't have to do this in the case where the dollar sign is the final character of the password.

As an example, if your password is "pas$word", from Linux bash we must connect as follows:

# mysql --host= --user=root --password=pas\$word
2/7/2018 2:21:13 AM

I was getting the same error after granting remote access until I made this:

From /etc/mysql/my.cnf

In newer versions of mysql the location of the file is /etc/mysql/mysql.conf.d/mysqld.cnf

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           =

(comment this line: bind-address =

Then run service mysql restart.


By default in MySQL server remote access is disabled. The process to provide a remote access to user is.

  1. Go to my sql bin folder or add it to PATH
  2. Login to root by mysql -uroot -proot (or whatever the root password is.)
  3. On success you will get mysql>
  4. Provide grant access all for that user.

GRANT ALL PRIVILEGES ON *.* TO 'username'@'IP' IDENTIFIED BY 'password';

Here IP is IP address for which you want to allow remote access, if we put % any IP address can access remotely.


C:\Users\UserName> cd C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin

C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.27 sec)

Query OK, 0 rows affected (0.25 sec)

This for a other user.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'testUser'@'%' IDENTIFIED BY 'testUser';
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Hope this will help


Do you have a firewall ? make sure that port 3306 is open.

On windows , by default mysql root account is created that is permitted to have access from localhost only unless you have selected the option to enable access from remote machines during installation .

creating or update the desired user with '%' as hostname .

example :

CREATE USER 'krish'@'%' IDENTIFIED BY 'password';

  1. Try to flush privileges again.

  2. Try to restart server to reload grants.

  3. Try create a user with host "". "%" appears to not allow all (it's weird)


In my case I was trying to connect to a remote mysql server on cent OS. After going through a lot of solutions (granting all privileges, removing ip bindings,enabling networking) problem was still not getting solved.

As it turned out, while looking into various solutions,I came across iptables, which made me realize mysql port 3306 was not accepting connections.

Here is a small note on how I checked and resolved this issue.

  • Checking if port is accepting connections:

    telnet (mysql server ip) [portNo]

  • Adding ip table rule to allow connections on the port:

    iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

  • Would not recommend this for production environment, but if your iptables are not configured properly, adding the rules might not still solve the issue. In that case following should be done:

    service iptables stop

Hope this helps.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]