
For VPS and dedicated server customers with root access. The short answer: a database that answers the internet (MySQL or MariaDB on port 3306, PostgreSQL on 5432) gets login attempts around the clock, and a national incident response team (CERT) reports it to our network and data centre provider. It is almost never needed: applications on the same server connect through localhost. You close it in three moves: see who connects from outside, make the database listen internally only, and let only the IPs that need it through the firewall, or use an SSH tunnel. Before closing, watch for the two cases that break: applications on another server and applications in Docker containers.
Who is affected when you close the port
| Who connects to the database | What happens |
| An application on the same server, with host localhost or 127.0.0.1 | Nothing: it keeps working. |
| An application in a Docker container connecting to the host’s database (through 172.17.0.1 or host.docker.internal) | It loses the connection if the database listens on 127.0.0.1 only. Put the database on the same compose network, or make it also listen on the Docker bridge address and limit that port in the firewall. |
| The database in a container published with -p 3306:3306 or -p 5432:5432 | Docker publishes it on every address and goes around ufw. Change it to 127.0.0.1:3306:3306, or remove the mapping. |
| Another of your servers, an office, a reporting tool | It loses the connection. Open the port to that IP only, or use an SSH tunnel. |
| You, with Workbench or DBeaver | Use an SSH tunnel: no open port needed. SSH tunnel, step by step. |
Closing the port, in the right order
|
|
|
|
|
|
|
|
| A database that was open may already have had visitors. Signs: new databases or tables with a ransom note, empty tables, accounts you never created. Do not pay: there is no guarantee at all that the data comes back. If you find signs that someone already got in, closing the port is not enough: the safest path is to reinstall the server and restore a clean copy (which backup to restore). Cleaning up in place is for people who know exactly what they are doing. See also is my VPS compromised?. |
| You do not need an open port to work on the database from home: an SSH tunnel takes Workbench or DBeaver to the server’s 127.0.0.1, and to anyone without your SSH key the port does not exist. On a VPS, root access is yours: we do not log in to the server and cannot change a firewall that runs inside it. If you lose SSH, tell us in the support ticket. |
|
Not sure which application connects to the database from outside? Send us the step 2 output in the support ticket. Open a support ticket |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon) See plans |











