MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

MySQL Basic Troubleshooting Guide: Service, Port 3306, Logs, and Crash Repair

mysql-troubleshooting

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.

Tasksystemd-based LinuxSysV init (legacy)
Check statussystemctl status mysqld
or systemctl status mysql
service mysqld status
Start / stop / restartsystemctl start|stop|restart mysqld/etc/init.d/mysqld start|stop|restart
or service mysqld start|stop|restart
If service is missingValidate installed package/service nameLegacy 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
CommandBest useWhat to look for
ss -ltnpModern listener checkPID/program bound to 3306
lsof -i TCP:3306Process-to-port mappingWhether mysqld owns the socket
netstat -lp / -tapLegacy systemsListener and owning process
ps … grep mysqldProcess existence checkRunning 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)
PlatformCommon default option files (original guide)
Linux/etc/my.cnf
/etc/mysql/my.cnf
/usr/etc/my.cnf
~/.my.cnf
WindowsC:\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)
ToolWhat it helps detectTypical signal
topCPU contention by processmysqld or non-MySQL process saturating CPU
vmstat 5CPU, memory, and I/O wait trendHigh wa values over multiple samples
iostat -x 5Disk saturation and latencyBusy device with sustained high utilization
Slow query logInefficient SQLRepeated 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 commandPurpose
pingCheck whether server is reachable
statusShort runtime summary (uptime, threads, queries)
variablesShow server variables and values
processlistList active server threads
flush-logsRotate and reopen logs
shutdownStop 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

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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Elastic Agent Commands Reference

Elastic Agent runs as an operating system service, so you start and stop it with systemd on Linux, launchd on macOS and the Service Control Manager on…

Read More

Jira on Linux: Installation and Configuration with Safer Service and Firewall Setup

Learn how to install Jira on Linux using Atlassian’s installer, manage it as a service, and expose port 8080 safely. This revision keeps the original references but updates the process for clearer, production-minded operations.

Read More

RHCSA EX200 Self-Study Curriculum and Hands-On Lab Manual

Gold-standard home-study roadmap for the Red Hat Certified System Administrator (RHCSA) exam EX200 Research cut-off: 2026-10-06 Primary authority: current official Red Hat EX200 page, Red Hat Certification…

Read More

Linux Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path

The Linux Administrator is responsible for the reliability, security, and day-to-day operational health of Linux-based infrastructure that supports enterprise applications, internal developer platforms, and shared IT services. This role ensures Linux systems are consistently configured, patched, monitored, backed up, and recoverable—while meeting organizational standards for availability, performance, and compliance.

Read More

Docker Tutorials: Docker Cgroup Drivers – Complete Guide

Introduction Docker uses cgroups (control groups) to manage resource constraints like CPU, memory, and I/O for containers. These cgroups are orchestrated through cgroup drivers that act as…

Read More

Understanding PID 1: Physical Servers, Virtual Machines, and Containers

Here’s a comprehensive, practical, and explanatory tutorial on the topic of PID 1 in physical servers, virtual machines, and containers, including why PID 1 is special in…

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

When troubleshooting MySQL, checking error logs and server status can help identify the real cause of a problem. Slow queries are also worth reviewing because they can affect the whole application. Tools like EXPLAIN can show how MySQL handles a query and where improvements may help. Before changing settings or repairing data, always take a backup and check its restore process. These habits make database troubleshooting safer and help prevent the same issues from returning.

1
0
Would love your thoughts, please comment.x
()
x