Search code examples
mysqlremote-accesssystem-administrationpymysql

Port 3306 not listening? Can't connect to MySQL remotely


I'm trying to connect to MySQL remotely with pymysql and I'm getting the error message:

(2003, "Can't connect to MySQL server on 'ip address' ([WinError 10061] 
No connection could be made because the target machine actively refused it)")

In my my.cnf file I've got bind-address set to 0.0.0.0 and skip-networking isn't there. Running "sudo netstat -atn" shows port 3306 is only listening on localhost:

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN

My firewall allowing traffic from 3306:

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
22/udp                     ALLOW       Anywhere
80/udp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
443/udp                    ALLOW       Anywhere
3306/tcp                   ALLOW       Anywhere
3306/udp                   ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
22/udp (v6)                ALLOW       Anywhere (v6)
80/udp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
443/udp (v6)               ALLOW       Anywhere (v6)
3306/tcp (v6)              ALLOW       Anywhere (v6)
3306/udp (v6)              ALLOW       Anywhere (v6)

I've restarted everything multiple times. I don't think its a MySQL authentication issue. I've got my users host set to '%'. How do I set the server to listen to any address on 3306, not just 127.0.0.1?

Edit: Here's the output from 'ps auxf | grep mysqld ':

root     15493  0.0  0.4  11988  2072 pts/0    S+   12:25   0:00          \_ 
grep --color=auto mysqld
root     25057  0.0  0.3   4448  1540 tty1     S    Jun13   0:00      \_ 
/bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql    25415  0.1  8.8 821124 44224 tty1     Sl   Jun13   8:04          \_ 
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-
dir=/usr/lib/mysql/plugin --user=mysql --skip-grant-tables --log-
error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --
socket=/var/run/mysqld/mysqld.sock --port=3306
mysql    15361  0.2  7.4 380788 37416 ?        Ssl  12:24   0:00 
/usr/sbin/mysqld
15042  0.0  7.4 380788 37164 ?        Ssl  12:21   0:00 /usr/sbin/mysql                            
d

Solution

  • 10061 is WSAECONNREFUSED, 'connection refused', which means either a firewall (unlikely) or more probably nothing listening at the IP:port you tried to connect to.