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) 1](https://maheshwaghmare.com/wp-content/uploads/2022/10/ERROR-2002-HY000-Cant-connect-to-MySQL-server-on-localhost-10061-1024x593.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 2](https://maheshwaghmare.com/wp-content/uploads/2022/10/mysqld-install-1024x593.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 3](https://maheshwaghmare.com/wp-content/uploads/2022/10/mysqld-initialize-1024x593.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 4](https://maheshwaghmare.com/wp-content/uploads/2022/10/services.msc_.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 5](https://maheshwaghmare.com/wp-content/uploads/2022/10/windows-os-services-start-mysql-service.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 6](https://maheshwaghmare.com/wp-content/uploads/2022/10/windows-os-services-successfully-started-mysql-service.png)
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 [Solved] ERROR 2002 (HY000): Can't connect to MySQL server on 'localhost' (10061) 7](https://maheshwaghmare.com/wp-content/uploads/2022/10/mysql-version-1024x593.png)