Check out example codes for "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)". It will help you in understanding the concepts better.

Code Example 1

> ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
> 
> service mysql start or service mysql start

Code Example 2

# Remove mysql
sudo apt-get remove --purge mysql\*

# Reinstall it
sudo apt install mysql-server mysql-client

# Test if it runs
sudo mysql

# You can install also thes pachages. Optionnaly
sudo apt install php7.4 php7.4-fpm php7.4-mysql php7.4-cgi php7.4-cli php7.4-common

#mesabo youbeyou

Code Example 3

sudo apt-get install mysql-server

Code Example 4

##	ERROR 2002 (HY000): 
##	Can't connect to local MySQL server through socket 

#### Follow below steps and you good to go... ####
sudo dpkg-reconfigure mysql-server-{version_number}
##version_number should be mysql version number installed
## Now try login in mysql shell
sudo mysql -u root -p

Code Example 5

# This is usually caused by the fact that the
# MySQL Server isn't even running
# On Windows, check your services, if its not running
# start it, or install and start it.

# On *nix, for this example Debian based
# Firstly see if it's even running
ps aux | grep mysql

# If you dont see any process other than your grep call,
# It's not running

# Assuming you have mysql-server installed
# Start it
sudo /etc/init.d/mysql start

# Otherwise install it, configure and start it up as above
sudo apt-get install mysql-server

# Goodbye 2002

Code Example 6

# this saved my ass
# first  you must perform a graceful shutdown of the server from the command line rather than powering off the server
shutdown -h now

# an additional method for getting it back up again when you run into this problem is to move mysql.sock

# to centos
mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock.bak

# to ubuntu
mv /var/run/mysqld/mysqld.sock /var/run/mysqld/mysqld.sock.bak

# restart mysql
service mysqld start

Learn ReactJs, React Native from akashmittal.com