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

Fiko Borizqy
1 min readOct 14, 2019
https://s24255.pcdn.co/wp-content/uploads/2014/03/Cant-connect-to-local-MySQL-server-through-socket.png

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

--

--

Fiko Borizqy

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