“Can’t Connect To Local MySQL Server Through Socket ‘/Var/Run/Mysqld/Mysqld.Sock’ (2)” on Docker ?


Check domysqld.sock and mysqld.pid exist or not. If not, inside the docker terminal, run these commands :

sudo touch /var/run/mysqld/mysqld.sock
sudo touch /var/run/mysqld/mysqld.pid
sudo chown -R mysql:mysql /var/run/mysqld/mysqld.sock
sudo chown -R mysql:mysql /var/run/mysqld/mysqld.pid
sudo chmod -R 644 /var/run/mysqld/mysqld.sock

Then, restart mysql service :

sudo service mysql restart

Still, if your mysql can’t connect to mysql. Run this method and restart the service of mysql (maybe you also need to restart the container if still can’t connect to mysql) :

sudo chown -R mysql:mysql /var/lib/mysql /var/run/mysqld

I wrote these tutorials for myself in future when I forget for the next steps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store