Which of the following answers refers to a port number assigned to the mysql database system?

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.

asked Feb 24, 2010 at 5:06

4

I did

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

And that indicated that I was using port 3306 and that my search for the error continues.

Andy

5,19023 silver badges34 bronze badges

answered Feb 24, 2010 at 5:16

AnkurAnkur

2,3697 gold badges22 silver badges24 bronze badges

1

The best way to actually know what application is listening to which interface and 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           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      25934/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      7964/dropbear

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.

answered Feb 24, 2010 at 6:04

sybreonsybreon

7,3851 gold badge20 silver badges20 bronze badges

5

Enter via terminal to mysql:

mysql -u root

and then type the following in the mysql prompt:

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

This worked for me.

answered Jan 23, 2018 at 1:43

If you really want to confirm that it is running on the port you can telnet into the port while 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.

answered Feb 24, 2010 at 5:43

AlexAlex

1,1036 silver badges12 bronze badges

MySQL defaults to port 3306 unless you specify another line in the /etc/my.cnf config file.

Unless your /etc/my.cnf contains something like

[mysqld]
port = 3308

Then it is very likely you are using the default port.

answered Feb 24, 2010 at 5:14

Dave CheneyDave Cheney

18.4k8 gold badges48 silver badges56 bronze badges

An alternative method to the ones already listed (and not as good but hey, it works).

prompt>lsof -n | grep 'mysql.*TCP'
mysqld     1564     mysql   10u     IPv4            3246456       0t0        TCP *:mysql (LISTEN)
prompt>cat /proc/1564/net/tcp
  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode
   0: 11AC11AC:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 14299 1 ffff88012a429a00 299 0 0 2 -1
   1: 017AA8C0:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 13871 1 ffff880129962080 299 0 0 2 -1
   2: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 12596 1 ffff880129960000 299 0 0 2 -1
   3: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 11459 1 ffff88012a429380 299 0 0 2 -1
   4: 00000000:8D58 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 11315 1 ffff88012a428d00 299 0 0 2 -1
   5: 00000000:0019 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 12940 1 ffff880129960680 299 0 0 2 -1
   6: 0100007F:177A 00000000:0000 0A 00000000:00000000 00:00000000 00000000   500        0 3600557 1 ffff8800672dee80 299 0 0 2 -1
   7: 0100007F:177B 00000000:0000 0A 00000000:00000000 00:00000000 00000000   500        0 3603871 1 ffff88012a42ee80 299 0 0 2 -1
   8: 0100007F:177C 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 3608169 1 ffff88012a42f500 299 0 0 2 -1
   9: 0100007F:177D 00000000:0000 0A 00000000:00000000 00:00000000 00000000   500        0 3615687 1 ffff88012a42e180 299 0 0 2 -1
  10: 0100007F:00C7 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 3608454 1 ffff8800672db400 299 0 0 2 -1
  11: 00000000:0CEA 00000000:0000 0A 00000000:00000000 00:00000000 00000000    27        0 3246456 1 ffff8800672dba80 299 0 0 2 -1
  12: 00000000:024B 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 12944 1 ffff880129961380 299 0 0 2 -1
  13: 00000000:006F 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 10657 1 ffff88012a428680 299 0 0 2 -1
  14: 00000000:01D1 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 12942 1 ffff880129960d00 299 0 0 2 -1
  15: 0100007F:1DD2 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 3631325 1 ffff8800672da700 299 0 0 2 -1
  16: 0100007F:990B 0100007F:177B 01 00000000:00000000 02:0002F5D8 00000000   500        0 3610110 2 ffff8800672df500 20 3 26 4 19
  17: 0100007F:177B 0100007F:990C 01 00000000:00000000 00:00000000 00000000   500        0 3610124 1 ffff88012a42d480 20 3 0 5 -1
  18: 0100007F:990D 0100007F:177B 01 00000000:00000000 02:00031144 00000000   500        0 3610142 2 ffff8800672d9380 20 3 0 5 -1
  19: 0100007F:177B 0100007F:990B 01 00000000:00000000 00:00000000 00000000   500        0 3610111 1 ffff8800672dc100 21 3 29 4 -1
  20: 0100007F:177B 0100007F:9949 01 00000000:00000000 00:00000000 00000000   500        0 3611026 1 ffff8800672dad80 20 3 0 5 -1
  21: 0100007F:9912 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000   500        0 3610249 2 ffff8800672de180 20 3 0 3 -1
  22: 0100007F:177B 0100007F:990D 01 00000000:00000000 00:00000000 00000000   500        0 3610143 1 ffff8800672de800 20 3 1 5 -1
  23: 11AC11AC:0016 480111AC:9074 01 00000000:00000000 02:0002BCFF 00000000     0        0 3608096 2 ffff88012a428000 20 3 1 5 16
  24: 11AC11AC:0016 480111AC:8485 01 00000000:00000000 02:0005819F 00000000     0        0 3615610 2 ffff88012a42c100 20 3 1 5 -1
  25: 0100007F:177B 0100007F:9923 01 00000000:00000000 00:00000000 00000000   500        0 3610494 1 ffff88012a42ce00 20 3 0 5 -1
  26: 0100007F:990F 0100007F:177B 01 00000000:00000000 02:0003117F 00000000   500        0 3610209 2 ffff8800672dd480 20 3 0 5 -1
  27: 0100007F:9949 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000   500        0 3611025 2 ffff8800672ddb00 20 3 0 3 -1
  28: 0100007F:90CF 0100007F:177B 01 00000000:00000000 02:00004637 00000000   500        0 4049147 2 ffff8800672dc780 20 3 1 5 -1
  29: 11AC11AC:0016 480111AC:C273 01 00000000:00000000 02:00021D06 00000000     0        0 3600488 4 ffff88012a42a700 20 6 31 4 34
  30: 0100007F:177B 0100007F:90CF 01 00000000:00000000 00:00000000 00000000   500        0 4049148 1 ffff8800672d8680 20 3 0 5 -1
  31: 11AC11AC:0016 480111AC:C7C3 01 00000000:00000000 02:00093A92 00000000     0        0 3603799 2 ffff88012a42ba80 20 3 26 5 31
  32: 0100007F:177B 0100007F:9912 01 00000000:00000000 00:00000000 00000000   500        0 3610250 1 ffff8800672da080 20 3 0 5 -1
  33: 0100007F:177B 0100007F:990F 01 00000000:00000000 00:00000000 00000000   500        0 3610210 1 ffff8800672d9a00 20 3 1 5 -1
  34: 0100007F:990C 0100007F:177B 01 00000000:00000000 02:00031147 00000000   500        0 3610123 2 ffff88012a42ad80 20 3 1 5 -1
  35: 0100007F:9923 0100007F:177B 01 00000000:00000000 02:0005D3D3 00000000   500        0 3610493 2 ffff88012a42e800 20 3 16 3 -1
prompt>grep '^mysql:' /etc/passwd
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
prompt>

The uid 27 line is the mysqld process' listening socket, and 0CEA is hex for 3306.

answered Feb 24, 2010 at 17:30

hlovdalhlovdal

1,08511 silver badges18 bronze badges

Ok, this works on my linux box, but I'm not sure that Unix will store the cnf file in the same place.

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

answered Feb 24, 2010 at 5:16

jonfhancockjonfhancock

2362 silver badges6 bronze badges

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

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.sock'  port: 3307  MySQL Community Server (GPL)

RalfFriedl

3,0484 gold badges12 silver badges17 bronze badges

answered Feb 4, 2019 at 6:22

Which of the following answers refers to a port number assigned to the mysql database system?

If you try this: $ grep port /etc/mysql/mysql.conf.d/mysqld.cnf

you will see which port you are looking for.

answered May 4, 2020 at 0:20

above commands did not help me in my mac.

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

answered Feb 19, 2019 at 17:52

3

What is the port number for MySQL database?

Port 3306 is the default port for the classic MySQL protocol ( port ), which is used by the mysql client, MySQL Connectors, and utilities such as mysqldump and mysqlpump.

Why MySQL port is 3306?

3306 port number is used by MySQL protocol to connect with the MySQL clients and utilities such as 'mysqldump'. It is a TCP, i.e Transmission Control Protocol.

What is port 33060?

systems (32768 - 61000). For example, the default MySQL X Protocol port is 33060, and the. default MySQL Administrative Connection Port is 33062.

What is localhost 3306?

The MySQL server. It can also include a port number. e.g. "hostname:port" or a path to a local socket e.g. ":/path/to/socket" for the localhost. If the PHP directive mysql. default_host is undefined (default), then the default value is 'localhost:3306'.