MySQL port 3306

MySQL Port 3306: Default Port, Changing It and Remote Access

MySQL and MariaDB listen on TCP port 3306 by default. MySQL 8 also listens on 33060 for the X Protocol used by MySQL Shell. Port 3306 should be reachable only from your application servers, not from the whole internet. A remote connection needs three things: the server listening on a network address (bind-address), a MySQL user allowed from your host, and a firewall rule for 3306.

Default port
3306 / TCP
X Protocol
33060 / TCP
MariaDB
3306 / TCP
Config file
my.cnf / my.ini
Expose to internet?
No
Check port 3306 on a server

Last updated:

How to find which port MySQL is using

From a MySQL session

SHOW VARIABLES LIKE 'port';

Linux

sudo ss -ltnp | grep -E 'mysqld|mariadbd'

Windows

netstat -ano | findstr :3306

How to change the MySQL port

Changing the port reduces automated scan noise but is not real protection. Restricting who can reach the port matters far more.

  1. 1

    Edit the configuration file

    Set port = 3307 in the [mysqld] section. The file is usually /etc/mysql/mysql.conf.d/mysqld.cnf on Ubuntu, /etc/my.cnf on RHEL and Rocky Linux, and C:\ProgramData\MySQL\MySQL Server 8.0\my.ini on Windows.

  2. 2

    Allow the new port in SELinux (RHEL family)

    Run sudo semanage port -a -t mysqld_port_t -p tcp 3307, or MySQL will fail to start on the new port.

  3. 3

    Restart MySQL

    Run sudo systemctl restart mysql (or mysqld, mariadb), or restart the MySQL service in Windows Services.

  4. 4

    Update clients and firewall rules

    Connect with mysql -h HOST -P 3307 -u USER -p and update application connection strings and firewall rules.

How to allow remote connections to MySQL

  1. 1

    Listen on a network address

    Ubuntu packages bind to 127.0.0.1 by default. Set bind-address = 0.0.0.0 (or the server's private IP) in [mysqld] and restart.

  2. 2

    Create a user for the remote host

    MySQL accounts include the client host. Run CREATE USER 'app'@'203.0.113.25' IDENTIFIED BY 'strong-password'; then GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'app'@'203.0.113.25';.

  3. 3

    Allow only that client in the firewall

    Run sudo ufw allow from 203.0.113.25 to any port 3306 proto tcp. In the cloud, limit the security group rule to the application server's address.

  4. 4

    Test the connection

    From the client run mysql -h db.example.com -P 3306 -u app -p. To check reachability only, use the open port checker or Test-NetConnection db.example.com -Port 3306.

Should port 3306 be open to the internet?

No. Internet-facing MySQL servers are scanned and brute-forced continuously. Keep 3306 private and use one of these instead:

  • An SSH tunnel for administration: ssh -L 3306:127.0.0.1:3306 user@db.example.com, then connect to 127.0.0.1:3306 locally.
  • A VPN or private network between application and database servers.
  • If a remote client must connect directly, allow only its IP and require TLS with require_secure_transport = ON.
  • Check from outside that 3306 is not exposed with the port scanner Databases preset.

Common MySQL connection errors

On Windows, the same timeout and refusal errors appear as error codes 10060 and 10061.

MySQL connection errors and what they mean
ErrorMeaningFix
ERROR 2003 (HY000): Can't connect to MySQL server (110)Timeout: a firewall drops traffic to 3306.Open 3306 for the client IP in the host firewall and security group.
ERROR 2003 (HY000): Can't connect to MySQL server (111)Refused: MySQL is not running or only listens on 127.0.0.1.Start MySQL and set bind-address.
ERROR 1130 (HY000): Host 'x' is not allowed to connectNo MySQL user exists for that client host.Create the user for the client's IP or hostname.
ERROR 1045 (28000): Access denied for userWrong password, or the user exists for a different host.Reset the password or check the host part of the account.
Authentication plugin 'caching_sha2_password' cannot be loadedAn old client does not support MySQL 8's default authentication.Update the client or connector library.

MySQL port FAQ

What port does MySQL use?

MySQL uses TCP port 3306 by default. MySQL 8 also uses 33060 for the X Protocol.

Is port 3306 TCP or UDP?

TCP. MySQL client connections never use UDP.

How do I find my MySQL port?

Run SHOW VARIABLES LIKE 'port'; in a MySQL session, or check which port mysqld listens on with ss -ltnp (Linux) or netstat -ano (Windows).

How do I change the MySQL port?

Set port = NEWPORT under [mysqld] in my.cnf or my.ini, allow the port in SELinux and the firewall, and restart MySQL.

Should I open port 3306 on my router?

No. Use an SSH tunnel or VPN instead. If remote access is unavoidable, allow only specific client IPs and require TLS.

What is port 33060?

It is MySQL's X Protocol port, used by MySQL Shell and the document store API. Regular clients and drivers use 3306.

References