Fix mySQL Error Cant connect to local MySQL server through socket /var/run/mysqld/mysqld.sock ERROR 2002 HY000


mysql error 2002 hy000
mySQL Error 2002 HY000:
# mysql

ERROR 2002 (HY000): 

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

If you try to start mysql server and you get the above error 2002 (HY000), the most common reason is that the mysql service is not running, in order to fix that you need to start the mysql server,

Solution:
# sudo service mysql start
 * Starting MySQL database server mysqld   [ OK ]

Now try to get into mysql prompt and you should be through!

root@b2391b608026:/# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

We can also check if the mysql service is running or not using the service status command,

sudo service mysql status
 * /usr/bin/mysqladmin  Ver 8.0.28-0ubuntu0.20.04.3 for Linux on aarch64 ((Ubuntu))
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version 8.0.28-0ubuntu0.20.04.3
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 7 min 22 sec

Threads: 2  Questions: 10  Slow queries: 0  Opens: 117  
Flush tables: 3  Open tables: 36  Queries per second avg: 0.022

If the device is not running you will see MySQL is stopped.

# sudo service mysql status
 * MySQL is stopped.
Advertisements
Try Out Code2care Dev Tools:

Advertisements



#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency