DBA Diaries

Thoughts and experiences of a DBA working with SQL Server and MySQL

Home All Articles How to Determine Which Port MySQL is Running On

How to Determine Which Port MySQL is Running On

Posted on May 9, 2016 Written by Andy Hayes Leave a Comment

MySQL defaults to port 3306 when installed but sometimes for another reason, it may be listening on a different port. In this post, I list some ways in which you can find out which port your MySQL instance is running on.

Using the MySQL configuration file to determine which port it is running on

If you are running linux, then this is an easy one liner. On my test machine, my config is stored in /etc/mysql:

cat /etc/mysql/my.cnf | grep port

On my test machine this returns

port            = 3306

If you are running Windows, then find your my.ini file and open it in a text editor such as notepad. Perform a search for the term – “port”

Using the MySQL client to determine the MySQL port

MySQL can tell you which port it is running on. Log into it and use the “show variables like ‘port{3a76cbff1b5ce5ace3bd34bbdd68f71285d81fb9af60114c7a6db80d3a8688de}'”;

[email protected]:~# mysql -uroot -p;
mysql> show global variables like 'port%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)

If you are using a client such as MySQL Workbench, you use the above syntax or click on “Server Status” over on the left hand side, for example in Windows, it looks like this:

how to find mysql port using MySQL workbench

Using the netstat command to check which port MySQL is running on

If you’re wanting to know how to check if mysql is running then there are some useful one line commands that can be run.

This command is very useful as a mysql port check either on a unix or windows operation system – “netstat” which is short for “network statistics”

netstat -tln | grep mysql

In the results below (unix OS), the port is listed in this section as “0 0.0.0.0:3306”

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1115/mysqld

If running on windows, you could do

netstat -anob

It’s a little hard then to find the one which is relevant as the list can be quite large, scrolling past quickly. It’s possible to pipe it to make the output page or dump it to file and then look for mysqld.exe in the list.

Paging example

netstat -anob | more

Dumping to file example

netstat -anob > output.txt

In each case find the mysqld.exe lines where the status is LISTENING

Related Posts:

  • How to set up MySQL Replication TutorialHow to set up MySQL Replication Tutorial
  • How to Setup MySQL Master Master ReplicationHow to Setup MySQL Master Master Replication
  • What is MySQL Replication and How Does It Work?What is MySQL Replication and How Does It Work?
Share this...
Share on Facebook
Facebook
Share on Google+
Google+
Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin
Pin on Pinterest
Pinterest
Share on Reddit
Reddit
Share on StumbleUpon
StumbleUpon
Share on Tumblr
Tumblr
Buffer this page
Buffer

Filed Under: All Articles, MySQL Administration Tagged With: mysql

About Andy Hayes

Andy Hayes is a DBA working with SQL Server since version 7.0. He has a wonderful wife and two beautiful children. He loves database technology, playing cricket, and blogging. He is passionate about sharing his experiences as a DBA and learning more to further his understanding and knowledge. You can follow me on Twitter, check out my Facebook page or follow me on Google+

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CAPTCHA
Refresh

*

Categories

  • All Articles (82)
  • Career Development (8)
  • MySQL Administration (18)
  • MySQL Performance (2)
  • SQL Server Administration (24)
  • SQL Server News (3)
  • SQL Server Performance (14)
  • SQL Server Security (3)
  • SQL Tips and Tricks (19)

Top 10 Popular Posts

  • Using sp_change_users_login to fix SQL Server orphaned users
  • How to shrink tempdb
  • How to Transfer Logins to Another SQL Server or Instance
  • How to Delete Millions of Rows using T-SQL with Reduced Impact
  • New T-SQL features in SQL Server 2012 – OFFSET and FETCH
  • MySQL SHOW USERS? – How to List All MySQL Users and Privileges
  • How to move tempdb
  • Using exec sp_who2 to help with SQL Server troubleshooting
  • Using DBCC FREEPROCCACHE to Clear SQL Server Procedure Cache
  • How to Install MySQL 5.5 on Ubuntu Server 12.04 LTS

Recent Posts

  • How to Setup MySQL Master Master Replication
  • How To Use SQL to Convert a STRING to an INT
  • How to set up MySQL Replication Tutorial
  • How to Use SQL CASE for Conditional Logic in Your SQL Queries
  • Using ISNULL in SQL Server to Replace NULL Values

Search

Connect

  • Twitter
  • Facebook
  • Google+
  • RSS

About

  • Cookie Policy
  • Disclaimer
  • About
Copyright © ‘2018’ DBA Diaries built on the Genesis Framework

This site uses cookies. We assume you are happy with cookies but click the link if you are not. Close