MySQL Port Numbers
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
MySQL, one of the world’s most popular open-source relational database management systems, communicates over a network using a standardized port. If you’re configuring MySQL, setting up firewall rules, or debugging network-related issues, it’s essential to understand which ports MySQL uses. In this guide, we’ll dive into the default MySQL port number and discuss related port considerations.
By default, MySQL uses port 3306 for client-server communication. When you install MySQL without any specific configurations regarding its port number, clients will try to connect to the server on port 3306.
mysql -h hostname -P 3306 -u username -p
MySQL can also use SSL for encrypted connections. When you configure MySQL to use SSL, it still uses port 3306 by default. The port number doesn’t change; instead, the data transmitted over the port is encrypted.
While the default port is 3306, you can configure MySQL to listen on a different port. To do this:
my.cnf or my.ini.port directive under the [mysqld] section.[mysqld]
port = 3307
3307).3306, necessitating a change.33060 by default.If you need to confirm which port your MySQL server is listening on:
From the MySQL prompt:
SHOW GLOBAL VARIABLES LIKE 'port';
From the command line, using netstat:
netstat -tuln | grep mysqld
If you’re running a firewall (e.g., iptables or ufw), ensure that you allow connections to the MySQL port. For example, with ufw:
sudo ufw allow 3306/tcp
Replace 3306 with your configured port if different.
Understanding MySQL’s port numbers and their configurations is essential for proper setup, maintenance, and security of your MySQL environment. Always ensure that any opened port is secured and monitored, irrespective of its number. Remember, while changing the default port can be part of your security strategy, it should never be the only strategy.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.