Ubuntu 16.04 MySql-5.7 upgrading error.

apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ...
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: 2003: Cant connect to MySQL server on 'localhost' (111) 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:  mysql-server-5.7

Before running command, checked status:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-04-11 13:32:11 EEST; 7s ago
  Process: 7842 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 7832 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 7841 (mysqld)
   CGroup: /system.slice/mysql.service
           └─7841 /usr/sbin/mysqld

Afrer upgrade command:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

As can see, before command service is successfuly runned, and seems what dpkg try to restart MySql service and at that moment fail with error mysql_upgrade: Got error: 2003 or mysql_upgrade: Got error: 2002.

Fixing:

  1. systemctl enable mysql
  2. systemctl start mysql
  3. apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up mysql-server-5.7 (5.7.17-0ubuntu0.16.04.2) ...
Checking if update is needed.
This installation of MySQL is already upgraded to 5.7.17, use --force if you still need to run mysql_upgrade

Check status again:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-04-11 13:43:04 EEST; 1min 56s ago
 Main PID: 10458 (mysqld)
   CGroup: /system.slice/mysql.service
           └─10458 /usr/sbin/mysqld