Port 3306 appears to be closed on my Ubuntu server
The problem was that the server was listening internally only.
Removing the line bind-address 127.0.0.1
from /etc/mysql/my.cnf
solved the issue.
Newer versions of Ubuntu (≥16.04) may have this line in /etc/mysql/mysql.conf.d/mysqld.cnf
.
My suggestion, if you are sure that the ports are closed (I find it weird for a VPS to have that port closed) is to change the configuration file of MySQL to use another.
Simply open the configuration file in the terminal, sudo nano /etc/mysql/mysql.conf
, and look for the [mysqld]
section. In it, look for the line that reads port = 3306
. Change it to another port not used and save the file.
Then simply either restart the VPS or restart the service, like sudo service mysql restart
.
Just to note that, if the file mysql.conf
is not in the one I mentioned above it can be in this other places:
/etc/my.conf
/etc/my.cnf
/etc/mysql/my.conf
And if the service
command does not work, then do this:
sudo /etc/init.d/mysql restart
If the problem persists then in my case I would check iptables (I would actually delete everything in iptables just to start fresh if this could be an option) or any other firewall-enabled option.
Since they are VPS, I would also check the VPS Control Panel to see if it has any option that can block ports.
Apart from that, I would run nmap
on the VPS to see what ports you have opened. You need to run it from outside the VPS to see what ports they have opened.
netstat -tuplen
is also a good idea to see what opened ports you have on the server and which ones are in LISTEN mode.
I use this method:
sudo ufw status
sudo ufw allow XXXX/tcp
# use a port other than the default/predictable 3306
# work outside, and close the door when you are done
sudo ufw deny XXXX/tcp
No need to change other configuration files, and no extra ports opened by default.