Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Log in Sign up

SPONSORED BY

Ask Question

How to check what port mysql is


running on
Asked 12 years, 8 months ago Modified 2 years, 6 months ago

Viewed 541k times

83
Locked. This question and its answers are
votes
locked because the question is off-topic
but has historical significance. It is not
currently accepting new answers or
interactions.

On my windows dev box mysql is running on


port 3306

How can I check what port it is running on the


unix server that I have to upload the app to.

mysql unix port

Share asked Feb 24, 2010 at 5:06


Ankur
2,369 7 22 24

That depends on how you can access the


server. Do you have ssh access, mysql client
access, or some web interface like
phpMyAdmin? – jonfhancock Feb 24, 2010 at
5:08

ssh access - through putty – Ankur Feb 24,


2010 at 5:09

Is this a shared host? If so, there may well be


multiple instances of MySQL running on it, each
on a different port. – John Gardeniers Feb 24,
2010 at 7:05

No it's a VM setup just for me, so there's only


one instance. – Ankur Feb 25, 2010 at 6:23

Comments disabled on deleted / locked posts / reviews

Sorted by:
10 Answers
Highest score (default)

104 I did

votes
mysql> SHOW GLOBAL VARIABLES
LIKE 'PORT';

And that indicated that I was using port


3306 and that my search for the error
continues.

Share

edited Feb 24, 2010 at 17:42


Andy
5,190 23 34

answered Feb 24, 2010 at 5:16


Ankur
2,369 7 22 24

1 This command helps to find out all global


variables. mysql> SHOW GLOBAL VARIABLES;
– arunkvelu Mar 4, 2019 at 9:59

Add a comment

43 The best way to actually know what


application is listening to which interface and
votes
on what port is to use netstat

You can do this as root:

netstat -tlnp

It will list out all the listening services like this:

Active Internet connections (only servers)


Proto Recv-Q Send-Q Local Address
tcp 0 0 0.0.0.0:3306
tcp6 0 0 :::22

The last column shows you that mysqld bound


itself to port 3306 listening on all interfaces.

In fact, this works for everything, not just


mysql. You can also use it non TCP sockets.

Share answered Feb 24, 2010 at 6:04


sybreon
7,365 1 20 20

2 the -p flag only works on linux, afaik. (definitely


not Mac OS X, at least) – jdizzle Mar 8, 2010 at
4:48

2 guess that you're stuck with lsof -i TCP


then. – sybreon Mar 9, 2010 at 5:18

The Linux command and windows command


vary slightly. For Windows, you must be
elevated, and replace the p with a b – IceMage
Feb 19, 2019 at 18:14

lsof -i TCP works and shows mysqld 777


aajapfmyd 45i IPv6 099899bafe45 0t0 TCP
localhost:33060 (LISTEN) on mac but why
the port shown is 33060 instead of 3060?
– iCantC Feb 3, 2020 at 9:58

i would also like to know the answer to the


above question commentor's question @iCantC
– frei Feb 25, 2020 at 7:35

Add a comment

7 Enter via terminal to mysql:

votes
mysql -u root

and then type the following in the mysql


prompt:

mysql> SHOW GLOBAL VARIABLES LIKE


'PORT';

This worked for me.

Share edited Jul 18, 2019 at 10:25


eem
103 4

answered Jan 23, 2018 at 1:43


IgnacioAinol
71 1 1
Add a comment

5 If you really want to confirm that it is running


on the port you can telnet into the port while
votes
the process is up like so:

telnet localhost 3306

You'll see it report that you're connected to


mySQL.

Alernatively, you can find the process's PID


using ps and grep:

ps -ef | grep mysql

and then put that pid into lsof to print out all
the open file descriptors. You'll find the port
the process is bound to near the top.

Share edited Jan 5, 2018 at 21:31


Community Bot
1

answered Feb 24, 2010 at 5:43


Alex
1,103 6 12
Add a comment

4 MySQL defaults to port 3306 unless you


specify another line in the /etc/my.cnf
votes
config file.

Unless your /etc/my.cnf contains something


like

[mysqld]
port = 3308

Then it is very likely you are using the default


port.

Share answered Feb 24, 2010 at 5:14


Dave Cheney
18.3k 8 48 56
Add a comment

3 An alternative method to the ones already


listed (and not as good but hey, it works).
votes

prompt>lsof -n | grep 'mysql.*TCP'


mysqld 1564 mysql 10u IPv4
prompt>cat /proc/1564/net/tcp
sl local_address rem_address st tx_que
0: 11AC11AC:0035 00000000:0000 0A 000000
1: 017AA8C0:0035 00000000:0000 0A 000000
2: 00000000:0016 00000000:0000 0A 000000
3: 0100007F:0277 00000000:0000 0A 000000
4: 00000000:8D58 00000000:0000 0A 000000
5: 00000000:0019 00000000:0000 0A 000000
6: 0100007F:177A 00000000:0000 0A 000000
7: 0100007F:177B 00000000:0000 0A 000000
8: 0100007F:177C 00000000:0000 0A 000000
9: 0100007F:177D 00000000:0000 0A 000000
10: 0100007F:00C7 00000000:0000 0A 000000
11: 00000000:0CEA 00000000:0000 0A 000000
12: 00000000:024B 00000000:0000 0A 000000
13: 00000000:006F 00000000:0000 0A 000000
14: 00000000:01D1 00000000:0000 0A 000000
15: 0100007F:1DD2 00000000:0000 0A 000000
16: 0100007F:990B 0100007F:177B 01 000000
17: 0100007F:177B 0100007F:990C 01 000000
18: 0100007F:990D 0100007F:177B 01 000000
19: 0100007F:177B 0100007F:990B 01 000000
20: 0100007F:177B 0100007F:9949 01 000000
21: 0100007F:9912 0100007F:177B 01 000000
22: 0100007F:177B 0100007F:990D 01 000000
23: 11AC11AC:0016 480111AC:9074 01 000000
24: 11AC11AC:0016 480111AC:8485 01 000000
25: 0100007F:177B 0100007F:9923 01 000000
26: 0100007F:990F 0100007F:177B 01 000000
27: 0100007F:9949 0100007F:177B 01 000000
28: 0100007F:90CF 0100007F:177B 01 000000
29: 11AC11AC:0016 480111AC:C273 01 000000
30: 0100007F:177B 0100007F:90CF 01 000000

The uid 27 line is the mysqld process' listening


socket, and 0CEA is hex for 3306.

Share edited Feb 25, 2010 at 22:10

answered Feb 24, 2010 at 17:30


hlovdal
1,075 11 18
Add a comment

1 Ok, this works on my linux box, but I'm not sure


that Unix will store the cnf file in the same
vote
place.

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

Share answered Feb 24, 2010 at 5:16


jonfhancock
236 2 6
Add a comment

0 you may try tailing the mysql log....try running

votes
shell$> tail -f /var/log/mysql/mysqld.log

while restarting mysql by

service mysqld stop/start

on another ssh terminal/tab. The port on


which its listening will be displayed in the log
as follows:

Version: '5.7.21-log' socket: '/tmp/mysql.

Share edited Feb 4, 2019 at 6:57


RalfFriedl
3,018 4 12 17

answered Feb 4, 2019 at 6:22


Anshuman Banerjee
101 1
Add a comment

0 If you try this: $ grep port


/etc/mysql/mysql.conf.d/mysqld.cnf
votes

you will see which port you are looking for.

Share answered May 4, 2020 at 0:20


Zeming Wang
1
Add a comment

-2 above commands did not help me in my mac.

votes
I used lsof -i TCP:3306 to find out the
mysqld process. which was actually listenting
into *.mysql

Share answered Feb 19, 2019 at 17:52


Prasath Rajan
1 2

1 This command can give you PID if the port


number is the default 3306. Original Poster
(OP) had a non-default number. – kubanczyk
Feb 19, 2019 at 20:01

I given a sample.. You can replace 3306 with


any other port. In this case its 3307.Command
is right though. – Prasath Rajan Feb 26, 2019 at
10:59

1 The correct way is using: sudo lsof -i


:3306 . – Bruno Wego Apr 3, 2019 at 18:16

Add a comment

Not the answer you're looking for? Browse other


questions tagged mysql unix port or ask your own
question.

The Overflow Blog

Five Stack Exchange sites are celebrating their ten


year anniversaries in Q4...

Another hard week in tech (Ep. 505)

Featured on Meta

Mobile app infrastructure being decommissioned

Related

122 How to check if a port is blocked on a Windows


machine?

2 Cannot SSH tunnel with PuTTY (Windows Vista) to


connect to MySQL on a Linux box

245 Environment variables of a running process on Unix?

4 Unable to connect to MySQL through port 3306

117 Why does the MySQL command line tool ignore the --
port parameter?

281 Check if port is open or closed on a Linux server?

2 Attempting to end anything running of port 3306

0 what is the port 33060 for mysql server ports in


addition to the port 3306

Hot Network Questions

Why would an Airbnb host ask me to cancel my request to


book their Airbnb, instead of declining that request
themselves?

When answering the Samaritan does Jesus allude to Isaiah


52:6?

Do trains travel at lower speed to establish time buffer for


possible delays?

Can the trombone be played left-handed?

Deciphering Work Profession from marriage certificate

Slick Hybrid Bike Tires on Steep Gravel Descent?

How were P2PK transactions made?

How to refuse a business trip due to low budget

What part of speech is ‘just’ in the sentence “It’s just me”?

Why do goggle lenses have "posts?"

Can a Soulknife Harengon add a Psionic Energy Die to


Initiative Checks?

Calculate numbers

Boosting definition clarification

The meaning of "lest you step in a thousand puddles with


fresh socks on"

Peano Axioms have models other than the natural numbers,


why is this ok?

How do I enable trench warfare in a hard sci-fi setting?

A not so simple C++20 circular queue

"Prime" pyramid

British 80s TV series about a toy soldier played by a real


actor

System.JSONException: Illegal value for primitive

Is AES-128 quantum safe?

Which orbiter is destroyed in "Star Trek V: The Final


Frontier" by the Klingon captain Klaa?

Ball pen mark on passport

Create 76 out of 1,2,3,4

SERVER FAULT

Tour Help Chat Contact Feedback

COMPANY

Stack Overflow Teams Advertising Collectives Talent About

Press Legal Privacy Policy Terms of Service Cookie Settings

Cookie Policy

STACK EXCHANGE NETWORK

Technology Culture & recreation


Your privacy Life & arts Science

Professional Businessall cookies”,


By clicking “Accept API Datayou agree Stack Exchange can
store cookies on your device and disclose information in
accordance with our Cookie Policy.

Blog Facebook Twitter LinkedIn Instagram


Accept all cookies Customize settings
Site design / logo © 2022 Stack Exchange Inc; user contributions
licensed under CC BY-SA. rev 2022.11.11.43030

You might also like