π ~1 min read
Table of contents
Symptom & Impact
Applications fail with cannot connect to local MySQL socket errors.
Environment & Reproduction
Appears after config edits, datadir moves, or service restarts.
sudo systemctl status mysql
mysql -uroot -p
ls -l /var/run/mysqld
Root Cause Analysis
mysqld not running, socket path mismatch, or directory permission problems.
Quick Triage
Check mysql service status and configured socket paths.
sudo journalctl -u mysql -n 120
grep -R socket /etc/mysql -n
ss -ltnp | grep 3306
Step-by-Step Diagnosis
Compare client and server socket config and validate runtime directory ownership.
sudo mysqld --verbose --help | grep socket | head -n 5
stat /var/run/mysqld
cat /etc/mysql/mysql.conf.d/mysqld.cnf | grep socket

Solution – Primary Fix
Correct socket path/permissions and restart mysql service.
Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo systemctl restart mysql

Solution – Alternative Approaches
Use TCP localhost connection while socket path issue is remediated.
mysql -h 127.0.0.1 -P 3306 -u root -p
Verification & Acceptance Criteria
Local and application connections succeed without socket errors.
mysqladmin ping
mysql -uroot -p -e 'select 1;'
Rollback Plan
Restore previous mysql config files if custom path change introduced regressions.
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf.bak /etc/mysql/mysql.conf.d/mysqld.cnf
sudo systemctl restart mysql
Prevention & Hardening
Template socket settings consistently across clients and server roles.
grep -R socket /etc/mysql -n
systemctl is-enabled mysql
Related Errors & Cross-Refs
Related to AppArmor denials, datadir mount issues, and auth plugin mismatches.
Related tutorial: View the step-by-step tutorial for Ubuntu 26.04 LTS.
View all Ubuntu 26.04 LTS tutorials on the Tutorials Hub β
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Ubuntu MySQL service administration and troubleshooting guides.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today β we respond within one business day.