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."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?Beginner