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

Posted November 25, 2020 11.2k views
MySQLUbuntu 20.04


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.

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.

Submit an Answer
1 answer

Hi there @ahsanharoonScubaDiver,

I would recommend checking if MySQL is up and running:

  • sudo systemctl status mysql

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

  • sudo systemctl start mysql

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


by Erika Heidi
A “LAMP” stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP. In this guide, we will install a LAMP stack on an Ubuntu 20.04 server.