MariaDB Port: Default Port Number, Configuration, and How to Change It
The MariaDB port is one of those quiet but critical details that can make or break a database connection. Whether you are installing MariaDB for the first time, moving an application between environments, or troubleshooting a stubborn "connection refused" error, knowing how the server listens for traffic is essential. By default, MariaDB uses port 3306, the same well-known port associated with MySQL, but that single number hides a surprising amount of configuration flexibility.
Understanding the MariaDB port means more than memorizing 3306. It means knowing when MariaDB uses TCP/IP, when it uses a Unix socket, how to change the port safely, and how to secure it against unwanted access. This guide walks through the practical details that database administrators, developers, and system engineers need to manage MariaDB networking with confidence.
Understanding the MariaDB Port and Its Role
The MariaDB port defines the network endpoint where the database server listens for client connections. When a client such as the mariadb command-line tool, a PHP application, or a Python service connects over TCP/IP, it must specify both a host and a port. If the port is wrong, blocked, or not listening, the client cannot reach the database even when the server process is running perfectly.
In most Linux distributions, MariaDB listens on port 3306 for TCP connections and also creates a local Unix socket for same-host communication. The TCP port is what matters for remote applications, containers, and multi-server setups. The Unix socket is often faster and more secure for local scripts because it bypasses the network stack entirely.
Default MariaDB Port 3306
Port 3306 is the official default for MariaDB and MySQL-compatible servers. When you install MariaDB from a package repository on Debian, Ubuntu, RHEL, Rocky Linux, or AlmaLinux, the server configuration normally includes port = 3306 inside a [mysqld] section. This consistency makes migration from MySQL to MariaDB easier because client libraries and connection strings often assume 3306 by default.
However, the default is not mandatory. Some hosting providers assign a different port to avoid conflicts or reduce automated scanning. In shared environments, multiple database instances may run on the same machine using ports such as 3307, 3308, or 3309. Always verify the actual port rather than assuming 3306 is active, especially on managed servers or containerized deployments.
How MariaDB Uses TCP/IP and Unix Sockets
MariaDB can accept connections through two main channels: TCP/IP and Unix domain sockets. TCP/IP uses the configured port and is required for remote clients. Unix sockets use a filesystem path, commonly /run/mysqld/mysqld.sock or /var/lib/mysql/mysql.sock, and are available only to processes on the same host. A local client may connect through the socket without ever touching the network port.
This dual behavior explains a common confusion: a website on the same server may connect fine while a remote tool fails. The local connection might be using the Unix socket, while the remote connection depends on the TCP port being open, bound to the correct interface, and allowed through the firewall. Checking both the socket path and the TCP port gives a complete picture of MariaDB connectivity.
Configuring and Troubleshooting the MariaDB Port
Changing or troubleshooting the MariaDB port requires editing the right configuration file and restarting the service. On many systems, the main configuration is split across files such as /etc/mysql/mariadb.conf.d/50-server.cnf, /etc/my.cnf, or /etc/my.cnf.d/server.cnf. The exact path depends on the operating system and installation method, so it helps to inspect the active configuration rather than guessing.
After any port change, clients must be updated to use the new value. Applications with hardcoded connection strings will fail until they are adjusted. Monitoring tools, backup scripts, replication configurations, and container health checks may also need updates. Treat the MariaDB port as part of the application contract, not just a server-side preference.
Changing the MariaDB Port in Configuration Files
To change the MariaDB port, locate the [mysqld] section in the server configuration and set a new value, for example port = 3307. If the directive is missing, add it under the correct section. Avoid placing it under [client] unless you also want local client tools to default to that port, because server and client settings serve different purposes.
On Debian and Ubuntu, you might edit /etc/mysql/mariadb.conf.d/50-server.cnf and then run systemctl restart mariadb. On RHEL-based systems, the file may be /etc/my.cnf.d/mariadb-server.cnf. After restarting, confirm the change with SHOW VARIABLES LIKE 'port'; or by running ss -tlnp | grep mariadbd. If SELinux is enforcing, a non-standard port may also require a policy update using semanage port -a -t mysqld_port_t -p tcp 3307.
Checking, Opening, and Securing the MariaDB Port
To check which port MariaDB is using, query the server with SELECT @@port; or inspect the listening sockets with ss -tlnp, netstat -tlnp, or lsof -iTCP -sTCP:LISTEN. If the port is not listening, verify that skip-networking is not enabled and that bind-address is not restricting connections to a different interface. The default bind-address is often 127.0.0.1, which allows only local TCP connections.
Opening the MariaDB port to remote clients should be done carefully. Use a firewall tool such as ufw allow from 203.0.113.10 to any port 3306 proto tcp or firewall-cmd --add-rich-rule to limit access by source IP. For public-facing servers, prefer a VPN, SSH tunnel, or private network instead of exposing the database port directly. Strong passwords, TLS encryption, and least-privilege database users remain essential even when the port is restricted.
As your infrastructure grows, the MariaDB port will likely appear in more places: Docker Compose files, Kubernetes services, Terraform modules, and CI/CD secrets. Document the chosen port, keep firewall rules aligned with it, and review remote access policies whenever an environment changes. A few minutes spent validating the port now can prevent hours of connection debugging later.