How do you check whether MySQL is running and which port it listens on?

BeginnerHands-onMySQL
Answer

Short answer

Check the service with systemctl status mysql (or mysqld), see the listening port with ss -tlpn | grep 3306, and confirm from inside MySQL with SHOW VARIABLES LIKE 'port';.

Commands

sudo systemctl status mysql          # Ubuntu (service name: mysql); RHEL: mysqld
sudo ss -tlpn | grep mysqld
# LISTEN 0 151 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=812,fd=23))
mysqladmin -u root -p status         # Uptime, threads, queries per second
mysqladmin -u root -p ping           # "mysqld is alive"
SHOW VARIABLES LIKE 'port';
SHOW VARIABLES LIKE 'bind_address';
SELECT VERSION();

What the bind address tells you

  • 127.0.0.1:3306 → only local connections. Remote apps can't connect.
  • 0.0.0.0:3306 → listening on all interfaces (then restrict with firewall/security groups).

Docker

docker ps --filter name=mysql
docker logs mysql | tail      # look for "ready for connections"

What to say in the interview

"systemctl status for the service, ss -tlpn to confirm it's listening on 3306 and on which address, and mysqladmin ping or SHOW VARIABLES for port and bind_address from the database side."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL