the netstat command is a useful tool for monitoring TCP/IP networks. It displays the route table, the actual network connection, and the status information of each network interface device, here I only use some of these features.
Common netstat parameters:-T,-u,-W, and-x indicate TCP, UDP, raw, and UNIX socket connections. -A flag will also display the socket waiting for connection (that is, in listening mode. -L display the listening (Listen) port.-N indicates that the port number is directly displayed instead of the port name by viewing/etc/service.-P indicates that the listening port is listed.Program
1) netstat-Tl
View the current TCP listening port
Active Internet connections (only servers)
PROTO Recv-Q send-Q local address foreign address State
TCP 0 0 *: rrac *: * listen
TCP 0 0 *: 34006 *: * listen
......
2) netstat-TLP
To view the current TCP listening port, You need to display the listening program name. It is easy to use when it is unclear about the MySQL listening port.
Active Internet connections (only servers)
PROTO Recv-Q send-Q local address foreign address State PID/program name
TCP 0 0 *: rrac *: * listen-
TCP 0 0 *: 34006 *: * Listen 23425/mysqld
......
3) netstat-Tl | grep 34006
Only view the MySQL listening port. The currently started MySQL port is 34006.
4) netstat-ta | grep 34006
TCP 0 0 *: 34006 *: * listen
TCP 0 0 Linux. Local: 34006 Linux. Local: 41485 established
TCP 0 0 Linux. Local: 34006 Linux. Local: 41486 established
...
TCP 0 0 10.3.2.35: 41488 10.3.2.35: 34006 established
TCP 0 0 10.3.2.35: 41489 10.3.2.35: 34006 established
TCP 0 0 10.3.2.35: 41490 10.3.2.35: 34006 established
Because the database and application programs are deployed on the same machine, the connection is displayed twice. You can use the-p parameter to display the PID and then grep the PID.
5) netstat-tap | grep 34006 | grep 23425
23425 is the current MySQL PID
TCP 0 0 *: 34006 *: * Listen 23425/mysqld
TCP 0 0 Linux. Local: 34006 Linux. Local: 41510 established 23425/mysqld
TCP 0 0 Linux. Local: 34006 Linux. Local: 41511 established 23425/mysqld
TCP 0 0 Linux. Local: 34006 Linux. Local: 41516 established 23425/mysqld