MySQL upgrade – Got error: 2002

free graphic of bed bug


If you manually control when MySQL starts on your workstation, during upgrade you get “Can’t connect to local MySQL server through socket”. The solution (login as root) that worked for me is to enable MySQL with “systemctl enable mysql”, do the upgrade, then disable again with “systemctl disable mysql”.

systemctl enable mysql

dpkg –configure mysql-server-5.7 (or apt-get dist-upgrade or whatever)

systemctl disable mysql

The error from my screen is as follows:

Setting up mysql-server-5.7 (5.7.20-0ubuntu0.16.04.1) …
insserv: warning: current start runlevel(s) (empty) of script `mysql’ overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `mysql’ overrides LSB defaults (0 1 6).
mysql_upgrade: Got error: 2002: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) while connecting to the MySQL server
Upgrade process encountered error and will not continue.
mysql_upgrade failed with exit status 11
dpkg: error processing package mysql-server-5.7 (–configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:

There were many opinions as to how to correct. The fix that worked for me was merely to enable MySQL  do the upgrade, then disable it again. Thanks to post on

lpuzio (leszekpuzio) wrote : #6


I had the same error. I solved this by one command:
sudo systemctl enable mysql

Than I had to start MySql:
sudo service mysql start

After this I was able to update:
sudo apt dist-upgrade

One could try to recreate this bug by disabling MySql before upgrade:
sudo systemctl disable mysql

I hope this helped you.


Comments are closed