How to fix: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) on Ubuntu - version = 20.04.1 LTS


For past few weeks i have been trying to install apache and mysql on my Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-54-generic x86_64)(digitalocean).

But i have been facing the same error again and again, no matter what i do this is the error i am facing "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

i have tried everything every solution but nothing worked.

i have installed mysql and apache in my debian server which is working fine but i don’t know why (here in digitalocean) i am facing this error again and again.

i have followed the digitalocean tutorial twice but whenever i reached at this "sudo mysql_secure_installation" step i got this error: "Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" i cant pass this step no matter what.

i need help how can i install all services without any issue i have to run a laravel website in this server.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @ahsanharoonScubaDiver,

I would recommend checking if MySQL is up and running:

  1. sudo systemctl status mysql

If it is not running, you can star tit with this command:

  1. sudo systemctl start mysql

I could suggest following this step by step tutorial on how to install Apache and MySQL here:

Regards, Bobby