Mysql

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.

Related Post

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.

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

3 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories