Error Installing mySql on Ubuntu 16.04

This answer is also in answer to 16.04 upgrade broke mysql-server but which I cannot answer as the admin locked it to 10 reputation.

The error in APT occurs during the upgrade of Ubuntu to 16.04 (xenial) and Mysql from 5.5 to 5.7. Due to some packaging issues the APT upgrade ends in limbo because the post installation script of Mysql-server-5.7 fails to complete.

To solve the problem, try these steps:

  1. apt purge mysql-server and apt autoremove to clean all traces of the old MYSQL. The database data will not be destroyed.
  2. Remove everything from /etc/mysql directory.
  3. Verify there is no old Mysql packages left installed: dpkg -l | grep mysql
  4. apt install mysql-server to install

If these steps end in the same incomplete install, try the next step:

  1. Tail -n 20 /var/log/mysql/error.log
  2. The errors could be a. bad password for debian-sys-maint b. no memory for Innodb

Solve 2a: You need to upgrade the Mysql system tables from 5.5 to 5.7

Edit my.cnf to include under '[mysqld]' the line "skip-grant-tables", service mysql start, and mysql_upgrade --force -u root -p

Solve 2b: You are short of memory for Mysql Innodb pool (are you on a micro-size server?)

Edit my.cnf to include under '[mysqld]' the line innodb_buffer_pool_size = 20M

the default innodb pool is 128M, that is tight in a 512M VM

To clear the APT error, do the post install again

dpkg --configure -a

Another good solution:

sudo apt-get purge mysql* && sudo apt-get install mysql-server

Completely removing mysql and reinstalling was the solution I eventually came to. Although I had tried to uninstall and reinstall once unsuccessfully (thus bringing me to ask this question). I tried a more thorough uninstall after finding the advice on this page: Uninstall MySQL completely

Following the uninstall directions there and reinstalling solved the problem.