ERROR 2002 : Can’t connect to MySQL server through socket

in this tutorial, We’ll Learn how to fix MySQL ERROR 2002 Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock.

Normally, This issue will occur when you connect the MySQL server through the command line, you might encounter a MySQL ERROR 2002 as follows:

mysql -uroot -proot

ERROR 2002 (HY000): Can’t connect to local MySQL server

through socket '/tmp/mysql.sock' (2)

If the mysql.sock socket file is not there in your filesystem, the ERROR 2002 that was mentioned above will appear.

When the MySQL server is started, this file is created, and it is deleted when the server is stopped.

How To Solve MySQL ERROR 2002

Please verify MySQL server is already installed and running on your computer.

if not installed then Please installed by following the below step

Install MySQL Server in Linux

Let’s install mysql-server and the mysql package using the below command.

apt-get install mysql-server mysql

Once you have the server installed, run the server with the following command:

sudo service mysql start
OR
sudo /etc/init.d/mysql start

The command will start the MySQL database server and create a mysql.sock file.

How To Install MySQL Server in Windows

Let’s verify MySQL service is running in the Services panel.

Step 1: Open the Windows Start menu and search for the Services panel to see the result below:

Step 2:

Scroll through the services list until you reach the MySQL services

Step 3: Check the status of the service if it’s stopped: you can run the service by clicking the Start the service link on the left pane. Otherwise, restart the MySQL server service.

You probably need to start the server in order for it to operate because the socket file is created when the MySQL server is started.

Now you can try to connect again to your MySQL server from the Command Line.

Leave a Reply

Your email address will not be published. Required fields are marked *