Database

MySQL and MariaDB Network Exposure on Linux

Reduce database exposure by restricting listeners, firewall access, database accounts, and remote administration paths.

MySQL and MariaDB should accept network connections only from systems that genuinely need them. On a single-server PHP deployment, the application often connects through a local Unix socket or loopback interface. Publishing port 3306 to the internet increases the attack surface and is rarely necessary for routine administration.

Inspect listeners and accounts

Check which addresses the database daemon is listening on:

sudo ss -lntp | grep 3306

Review database users and their permitted hosts using an authorized database account. A user granted access from % may be reachable from any source that can reach the listener, subject to authentication and firewall rules. Prefer a specific application host or a local-only account when appropriate.

Restrict the listener

The bind-address setting controls which local interfaces the server listens on. A local-only configuration may use:

[mysqld]
bind-address = 127.0.0.1

The configuration file location and service name vary. Validate the setting against the actual topology before restarting MariaDB or MySQL. If a separate application server must connect, bind to a private interface and restrict access with a firewall and network ACL. Do not expose the database on a public interface simply to make remote phpMyAdmin or a desktop client work.

Secure accounts and transport

Create separate least-privilege accounts for applications, migrations, backups, and administration. Grant only the required database and table permissions. Use TLS for traffic crossing a network, protect credentials, and rotate secrets if they have been exposed. Avoid using the database root account in application configuration.

Verify from both sides

After changing the listener, test local application connectivity and expected remote administration paths. Confirm that port 3306 is closed from untrusted networks. Check database logs for rejected connections and verify that backups still work. On cPanel, coordinate with WHM and the provider's database configuration; panel-managed settings may be regenerated, and remote MySQL access may have its own allowlist.

Share this page Help other developers discover this resource.