Question

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

ramana_sharma@ramana:~$ mysql --version mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper ramana_sharma@ramana:~$ mysql -uroot -proot0 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) ramana_sharma@ramana:~$ mysql -u root -p Enter password: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) ramana_sharma@ramana:~$ services mysql start No command ‘services’ found, did you mean: Command ‘service’ from package ‘init-system-helpers’ (main) services: command not found ramana_sharma@ramana:~$ /etc/init.d/mysql start bash: /etc/init.d/mysql: No such file or directory ramana_sharma@ramana:~$ #/usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock ramana_sharma@ramana:~$ /etc/init.d/mysql start bash: /etc/init.d/mysql: No such file or directory ramana_sharma@ramana:~$ sudo service mysql restart [sudo] password for ramana_sharma: Failed to restart mysql.service: Unit mysql.service not found. ramana_sharma@ramana:~$ sudo nano /etc/mysql/my.cnf ramana_sharma@ramana:~$ systemctl enable mysql Failed to execute operation: No such file or directory

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
December 2, 2022
Accepted Answer

Can you try to examine the server logs in order to track down more detailed information bout the issue?

On Ubuntu systems, the default location for MySQL is /var/log/mysql/error.log In many cases, the error logs are most easily read with the less program, a command line utility that allows you to view files but not edit them:

  1. sudo less /var/log/mysql/error.log

If MySQL isn’t behaving as expected, you can obtain more information about the source of the trouble by running this command and diagnosing the error based on the log’s contents.

You can also use the journalctl command

https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs

The innodb_force_recovery is added to the my.cnf file in case of InnoDB corruption, but you need to use that as a last resort option.

Regards

This issue happen because MySQL or MariaDB server was not started.

service mysql status

It will show stop. Try starting.

service mysql start

Yeh Working now :)

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.