How to Identify the MySQL Port

JULY 24, 2024 • WRITTEN BY ROMAN AGABEKOV
The default MySQL port is 3306 for classic MySQL connections over TCP. If you already have a SQL session, check the server’s configured port with SHOW GLOBAL VARIABLES LIKE 'port';. If you’re setting up an application connection, use the port listed for the endpoint the application connects to.

Check the port from a MySQL session

Run this in an existing session on the instance you want to check:
SHOW GLOBAL VARIABLES LIKE 'port';
Read the Value column in the port row. A value of 3306 means that instance is configured to use the default classic TCP port. You can read the setting even from a Unix socket session. It doesn’t tell you whether TCP is enabled or whether your application can reach the server.

Find the port your application should use

Check the host and port together in your application’s connection settings or in the connection details for your managed database. A proxy or a container port mapping can expose a different port to the client. For example, if a container maps host port 13306 to MySQL port 3306, a client connecting through that mapping uses 13306 on the host, even though MySQL reports 3306.
For a self-managed server, look for port under [mysqld] in the option files used by that instance. If you don’t see it in one file, another file or a startup option can still set it.

If you can’t connect

Once you have the endpoint, check whether MySQL is running and accepting connections. The guide separates service status, a response from the endpoint, and a successful SQL login.
Once the connection works, see what Releem monitors in MySQL, including database latency and MySQL metrics.

Article by

  • Founder & CEO
    Roman Agabekov has 17 years of experience managing and optimizing MySQL and MariaDB in high-load environments. He founded Releem to automate routine database management tasks like performance monitoring, tuning, and query optimization. His articles share practical insights to help others maintain and improve their databases.