
Originally published on 2013-05-15; fully revised and updated.
MySQL incidents are often a mix of service state, configuration mistakes, port conflicts, and storage pressure. This guide gives a practical troubleshooting sequence for DevOps and operations teams, with command examples you can run on Linux hosts and notes for legacy setups still using older init scripts.
Fast triage workflow
Use this order to avoid jumping between unrelated checks and to quickly isolate whether the problem is process, network, config, or storage related.
flowchart TD
A[Locate mysql and mysqld binaries] --> B[Check mysqld service status]
B --> C{Running}
C -- no --> D[Read error log and my.cnf paths]
D --> E[Fix config, permissions, or disk issues]
E --> F[Start service again]
C -- yes --> G[Check port 3306 listener and socket]
G --> H{Conflict found}
H -- yes --> I[Stop conflicting process or change port]
H -- no --> J[Test login and mysqladmin status]
J --> K[Review slow queries and host performance]
Confirm MySQL binaries and service state
Start by confirming the client binary location, then verify whether mysqld is running.
which mysql
locate mysql
ps -ef | grep [m]ysqld
Service control commands differ by init system. Many older guides use SysV-style commands; modern distributions usually use systemd.
| Task | systemd-based Linux | SysV init (legacy) |
|---|---|---|
| Check status | systemctl status mysqld or systemctl status mysql | service mysqld status |
| Start / stop / restart | systemctl start|stop|restart mysqld | /etc/init.d/mysqld start|stop|restart or service mysqld start|stop|restart |
| If service is missing | Validate installed package/service name | Legacy registration sometimes used chkconfig with scripts under /etc/init.d |
Check port 3306 binding and process conflicts
If MySQL reports Address already in use, verify which process owns TCP 3306.
ss -ltnp | grep :3306
lsof -i TCP:3306
netstat -lp | grep 3306
netstat -tap | grep mysql
ps -aux | grep mysql
| Command | Best use | What to look for |
|---|---|---|
| ss -ltnp | Modern listener check | PID/program bound to 3306 |
| lsof -i TCP:3306 | Process-to-port mapping | Whether mysqld owns the socket |
| netstat -lp / -tap | Legacy systems | Listener and owning process |
| ps … grep mysqld | Process existence check | Running daemon and possible duplicates |
If 3306 is not listening under mysqld, either MySQL is down or configured for another port/socket in my.cnf.
Find my.cnf and verify critical settings
When startup or connectivity fails, confirm configuration file location and validate key directives.
whereis my.cnf
locate my.cnf
find / -name my.cnf
strace mysql ";" 2>&1 | grep cnfCode language: JavaScript (javascript)
| Platform | Common default option files (original guide) |
|---|---|
| Linux | /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf |
| Windows | C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf C:\Program Files\MySQL\MySQL Server 5.5\my.ini C:\Program Files\MySQL\MySQL Server 5.5\my.cnf |
Important parameters to verify in my.cnf:
- datadir (data directory path)
- log-error (error log file path)
- pid-file (daemon PID file path)
- tmpdir
- default-character-set
- default-storage-engine
- innodb_data_home_dir (if used)
Diagnose startup failures from logs and filesystem state
If mysqld will not start, check logs first, then ownership/permissions of datadir and available disk space.
# Locate configured log path in my.cnf
grep -R "log-error\|datadir\|pid-file" /etc/my.cnf /etc/mysql/my.cnf 2>/dev/null
# Review error output
tail -n 200 /var/log/mysqld.log
# or (systemd hosts)
journalctl -u mysqld -n 200 --no-pager
# Check data directory permissions and free space
ls -ld /var/lib/mysql
df -hCode language: PHP (php)
For local hostname resolution issues, verify localhost mapping exists:
grep "127.0.0.1" /etc/hostsCode language: JavaScript (javascript)
Recover crashed tables
The original guide shows table-crash errors during startup and uses SQL repair plus mysqlcheck. Start with targeted repair, then broaden if needed.
mysql -u root -p
REPAIR TABLE database1.table1;
SHOW CREATE DATABASE database1;Code language: CSS (css)
# Optimize + auto-repair one database
mysqlcheck -u username -p -o --auto-repair -v --optimize database_name
# Check/repair all databases
mysqlcheck -u root -p --auto-repair --check --optimize --all-databasesCode language: PHP (php)
Note: behavior differs by storage engine. Validate engine-specific recovery steps before running repair operations broadly.
Quick performance triage on host and MySQL
Use short-interval OS metrics and then correlate with MySQL slow queries and error logs.
top
vmstat 5
iostat -x 5
# If slow query logging is enabled, inspect the log configured in my.cnf
# and review long-running statementsCode language: PHP (php)
| Tool | What it helps detect | Typical signal |
|---|---|---|
| top | CPU contention by process | mysqld or non-MySQL process saturating CPU |
| vmstat 5 | CPU, memory, and I/O wait trend | High wa values over multiple samples |
| iostat -x 5 | Disk saturation and latency | Busy device with sustained high utilization |
| Slow query log | Inefficient SQL | Repeated high-latency queries |
Use mysqladmin for quick health checks
mysqladmin is useful for lightweight checks without entering the interactive MySQL shell.
mysqladmin -h hostname -p ping
mysqladmin -h hostname -p status
mysqladmin -h hostname -p variables
mysqladmin -h hostname -p processlist
mysqladmin -h hostname -p flush-logs
mysqladmin -h hostname -p flush-status
mysqladmin -h hostname -p shutdown
| mysqladmin command | Purpose |
|---|---|
| ping | Check whether server is reachable |
| status | Short runtime summary (uptime, threads, queries) |
| variables | Show server variables and values |
| processlist | List active server threads |
| flush-logs | Rotate and reopen logs |
| shutdown | Stop server cleanly |
Connectivity checks from clients
For network-level troubleshooting, test TCP reachability from the calling host.
telnet your_host_name 3306
# alternative if telnet is unavailable
nc -vz your_host_name 3306Code language: PHP (php)
References from the original post
- http://dev.mysql.com/doc/refman/5.5/en/mysqladmin.html
- http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html
- http://www.linux-mag.com/id/7473/
- http://dev.mysql.com/doc/refman/5.1/en/starting-server.html
Best practices and common pitfalls
- Always read the MySQL error log first before restarting repeatedly.
- Do not assume service name is always mysqld; some systems use mysql.
- Verify datadir ownership and free disk space during startup failures.
- Confirm who owns TCP 3306 before changing configuration.
- Use staged repair: single table, then single database, then all databases only when necessary.
- Capture baseline metrics (CPU, memory, disk, slow queries) before and after fixes.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals