MySQL Port Connection: An Easy Guide
MySQL is an open-source relational database management system used to store and query data across a network. It is the most widely adopted open-source database. However, whether you're connecting directly or through a client, you need to provide credentials, the hostname, and the MySQL DB port number. In most deployments, Port 3306 is the standard TCP port. Most tools use this MySQL default port number 3306 to connect unless a different port is configured.
In this guide, you will find illustrated answers to different MySQL port-related questions. Let us take a closer look at what kinds of ports there are, what is the default port in MySQL, and how to connect to the MySQL port from the command line.
How to specify MySQL port in the command line
The correct connection parameters, such as the hostname assigned to your computer, the username, and the password associated with your MySQL account, must be used in the client software in order to connect to the MySQL server. There is a default value for each connection parameter, but you can alter those according to your needs using program options provided either from the command line or in an option file.
To make MySQL command line specify port, add the -P <port> (uppercase P) or the --port=<port> option to your MySQL command.
- Localhost is used as the default hostname.
- If no username is specified, the MySQL client defaults to the username of the currently logged-in user.
- As neither
--passwordnor-pare used, no password is provided in the command line. - The default database name for MySQL is taken from the first non-option parameter, if provided. Otherwise, a default database is not chosen.
Define the relevant parameters in the command line to explicitly specify the hostname, username, and password. You can use the database name option to select a default database.
Database connection and configuration have never been easier with dbForge Studio for MySQL. Simply fill in the database connection properties as shown in the video, and save time using the built-in Import and Export wizards. Learn how to connect to a MySQL database using this full-featured MySQL GUI:
What is the default port for MySQL Server?
The default MySQL database port is 3306. Most programs use this port automatically, but it may vary depending on configuration. For security reasons, the port number can be changed, especially if the default port is already in use by another application.
The MySQL protocol connects to utilities like mysqldump and MySQL client software using the default port.
Is MySQL port 3306 secure?
The MySQL server is vulnerable to attacks while the default port 3306 is exposed. If the user wants to access the database remotely, they must look into other secure options.
It is worth considering using an SSH tunnel instead of opening the default 3306 MySQL port. Another alternative is to limit the IP addresses that can access the port in order to prevent suspicious hosts from connecting.
Any client software that attempts to connect to the server must have the --port=portNumber option specified if your MySQL server is listening on a port other than 3306.
How to open MySQL port 3306 on a Windows/Linux firewall?
To open a MySQL port, allow TCP/3306 only from trusted IPs and ensure MySQL listens on the right interface (bind-address). Replace <YOUR_IP> with your source IP, then run the command for your OS:
- Windows (PowerShell): Create an inbound rule allowing TCP/3306 from a specific IP.
New-NetFirewallRule ` -DisplayName "MySQL 3306" ` -Direction Inbound ` -Protocol TCP ` -LocalPort 3306 ` -RemoteAddress <YOUR_IP> ` -Action Allow
- Ubuntu/Debian (UFW): Allow TCP/3306 from a specific source.
sudo ufw allow from <YOUR_IP> to any port 3306 proto tcp
- RHEL/CentOS (firewall): Add a persistent rich rule and reload.
sudo firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=<YOUR_IP> port protocol=tcp port=3306 accept' sudo firewall-cmd --reload
Prefer SSH/VPN and TLS; avoid open rules like 0.0.0.0/0.
Even though the default port is 3306, MySQL does not always use it. Any client software that attempts to connect to the server must specify the port using -P portNumber or --port=portNumber if your MySQL server is listening on a port other than 3306.
Types of MySQL ports
MySQL features support a wide range of ports that serve different purposes. Let us take a closer look at each one of those types.
Connection ports between the client and the server
The MySQL client, utilities like mysqldump, and MySQL connectors all use the 3306 default port. It's also the MySQL protocol standard port. Such clients as MySQL router, MySQL Shell, and MySQL connectors support the protocol.
MySQL connection port for administration
For administrative connections, the MySQL server supports TCP/IP port settings. This port expands the administrative connection choices available on the network interface for regular connections.
Shell ports for MySQL
MySQL Shell is a code and client editor for experienced users. Both the conventional MySQL and the X Protocol are supported by MySQL Shell.
Additionally, MySQL supports features such as high-availability ports, key management, the Memcached protocol, and external authentication.
How to check which port MySQL is using?
Port usage is largely determined by the components in use, the applications that are enabled, how those applications communicate, and the overall characteristics of the MySQL ecosystem.
The recommended practice is to configure ports to support all required components while strictly limiting access from untrusted hosts.
There are a few different techniques to figure out on which port your MySQL server is listening. When you are already connected to the MySQL server, you can
still check the port number that was used for this particular connection. To do this, execute the following command: SHOW VARIABLES LIKE 'port';.
Checking MySQL port on Ubuntu
To check MySQL port Ubuntu, run the following command:
sudo netstat -tulnp | grep 3306
There are also such types as high-availability ports, key management, Memcached Protocol, and external authentication ones.
If you are using Windows, you can find the MySQL port number in the configuration file:
- Navigate to the .ini file. It is located in the MySQL installation directory, e.g. C:\ProgramData\MySQL\MySQL Server 9.6\.
- Open the .ini configuration file using Notepad or another text editor.
- Locate the
portparameter to determine on which port MySQL is listening.
Changing your default MySQL port can protect you from brute-force programs that gain unwanted access. While using non-standard ports can improve your security, it only does so by lengthening the time it takes for a hacker to succeed. As a result, having extra security measures in place besides changing the port would be beneficial. Another reason you might need to change ports is if the usual 3306 is already in use.
Overview of MySQL port numbers: 3306, 33060, 33061, 33062
MySQL uses ports for different purposes. Let's review them in detail.
Port 3306 (TCP)
MySQL clients connect to the MySQL server through port 3306 by default. Communication on this port can be encrypted if TLS/SSL is configured. Also, unless the X Protocol is used, communication on this port flows from client to server.
Port 33060 (TCP)
This is the X Protocol port (mysqlx_port), used by clients such as MySQL Router, MySQL Connectors, and MySQL Shell. It is derived by multiplying the classic protocol port by 10: for example, if the classic protocol uses the default port 3306, then the X Protocol port is 33060. Communication over this port is encrypted using TLS, ensuring secure data exchange between the client and the server.
Port 33062 (Default TCP/IP)
Communication over this port is encrypted and occurs between the client and the server. It's worth mentioning that it is specifically configured to support administrative connections, providing an interface for tasks such as user management, server configuration, log viewing, and data export and import.
Port 33061 (TCP/IP)
Common MySQL Shell ports include 33061/TCP, 33060/TCP, and 3306/TCP. When running an InnoDB Cluster, the use of port 33061/TCP is mandatory. Communication over this port is encrypted, and its primary purpose is to verify a server during InnoDB Cluster configuration.
That's it! We hope this guide has been helpful; and just in case you're in search of a tool to help you manage MySQL most effectively, we'd love to suggest dbForge Studio for MySQL, our ultimate IDE for MySQL database administration, conveniently available for a free 30-day trial.
FAQ
netsh advfirewall firewall show rule name=all command and press Enter.
The output will contain all blocked and active ports configured in the firewall.
- MySQL listens on a different port.
- MySQL is not listening on TCP/IP.
- MySQL is bound to a local interface only.
- A firewall or cloud security rule blocks 3306.
- Your account or host is not allowed.
- Another service uses 3306.
--host=localhost allows the MySQL client to connect via Unix sockets, which bypass the network stack and are faster than TCP/IP. In this mode, the --port parameter is ignored. To force TCP/IP and use a specific port (for example, when running multiple servers), use --host=127.0.0.1 or --protocol=tcp. On Windows, localhost always connects over TCP/IP (127.0.0.1), since sockets aren't supported.
telnet + IP address or hostname + port number to run the telnet command and test the port status.
If the port is open, the system will display the message: "Connected to 10.17.XXX.XXX".
netstat -a -b command to see the list of applications that are using different ports. Look for the one using 3306.
Then, you can end this process in Windows Task Manager.
SHOW VARIABLES LIKE 'port' or ss -ltnp | grep 3306, and ensure that neither a firewall/security group nor a restrictive bind-address is blocking access. When remote access is required, allow TCP/3306 only from trusted IPs or use an SSH tunnel. Alternatively, you can configure the server to use a different port (e.g., 3307) and connect with -P 3307, or use the local UNIX socket when connecting directly on the server.