[Solved] ERROR 2002 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

Advertisement

Some time on Windows Operating System we see an error: ERROR 2002 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

You may have something similar error as below screenshot:

[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 1
[Solved] ERROR 2002 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

The issue behind the “ERROR 2002 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)” error is the Windows Operating System MySQL service is not started.

You can start the service by simply following below steps:

Step 1: Install MySQL with the command mysqld –install Step 1: Install MySQL with the command mysqld –install

You need to execute the below command:

mysqld --install

Open CMD/Command Prompt and execute the command as below:

[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 2
mysqld –install

Top ↑

Step 2: Initialize MySQL with mysqld –initialize Step 2: Initialize MySQL with mysqld –initialize

Keep open the terminal and execute the below command:

mysqld --initialize
[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 3
mysqld –initialize

Top ↑

Step 3: Start the MySQL Service in Windows Operating System Step 3: Start the MySQL Service in Windows Operating System

  • Press CTRL + R, or Goto start and type “Run“.
  • And type the services.msc as below screenshot:
[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 4
services.msc

You will see the Services screen.

Now, Search for MySQL.

You’ll see something like below screenshot:

[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 5
MySQL Service

Now, At the left, you can see the Start the service.

Click on Start.

You can see after that something like below:

[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 6
MySQL Service Successfully Started

Top ↑

Done! MySQL will works Done! MySQL will works

To confirm that MySQL is working as expected. Execute the below command:

mysql --version
[Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 7
mysql –version

Leave a Reply