Search code examples
phpmysqllinuxunixdatabase-administration

ERROR 2003 (HY000) while trying to connect to mysql remotely


I am trying to connect to mysql remotely. Because this is such a common question I read several tutorials/questions but I keep getting this error: ERROR 2003 (HY000): Can't connect to MySQL server on 'the-ip-address' (60) I edited the /etc/mysql/my.cnf and commented the line of bind_address like this:

#bind-address = 127.0.0.1

After that I ran:

$ sudo service mysql restart

with the output of: mysql stop/waiting mysql start/running, process 9853

mysql is running on default port: 3306

Using the user with which I am trying to connect remotely is working locally on the server (I can connect to the mysql from the server).

In phpmyadmin I configure these users: user@localhost user@127.0.0.1 user@87.45.34.23

Then I am trying to connect with the following:

mysql -u user -p -h 87.45.34.23

Maybe I am missing something... Thank you in advanced

UPDATE As @Geoffrey suggested in the comments the problem was with a firewall. For this reason I will accept his answer although the answer itself is not for that but in the comments he was right.


Solution

  • Connection refused means the MySQL server is not listening or is firewalled.

    By commenting out the bind line, MySQL doesn't bind to anything and only allows local socket access, you need to bind it to either the local IP, or all IPs by specifying 0.0.0.0

    Also ensure that skip-networking is not set anywhere.