16.04 upgrade broke mysql-server

The instructions @andrew-beerman posted are on the right track, though they aren't quite clear to me and seem to recommend more than is necessary. I pieced together the answer from the above and a helpful post in the bug thread.

These are the steps I took to correct this:

  1. Back up your my.cnf file in /etc/mysql and remove or rename it

    sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
    
  2. Remove the folder /etc/mysql/mysql.conf.d/ using

    sudo rm -r /etc/mysql/mysql.conf.d/
    
  3. Verify you don't have a my.cnf file stashed somewhere else (I did in my home dir!) or in /etc/alternatives/my.cnf use

    sudo find / -name my.cnf
    
  4. Backup and remove /etc/mysql/debian.cnf files (not sure if needed, but just in case)

    sudo mv /etc/mysql/debian.cnf /etc/mysql/debian.cnf.bak
    sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7
    sudo apt install mysql-server
    
  5. In case your syslog shows an error like "mysqld: Can't read dir of '/etc/mysql/conf.d/'" create a symbolic link:

    sudo ln -s /etc/mysql/mysql.conf.d /etc/mysql/conf.d
    

    Then the service should be able to start with sudo service mysql start.

That got it working!


Today I got the same problem, after trying many solutions i found that the problem was the command sudo systemctl disable mysql.service that i used to disable MySQL auto starting, so to get it working i re-enabled again MySQL server using the command sudo systemctl enable mysql.service and run again the upgrade process and it terminated perfectly.


Your error message contains this line:

subprocess installed post-installation script returned error exit status 1

However, this installed post-installation script is not mentioned by name. After much tinkering, I found out that its name is (in my case) /var/lib/dpkg/info/mysql-server-5.7.postinst.

Open this file with sudo vi /var/lib/dpkg/info/mysql-server-5.7.postinst, or your preferred editor.

At the top, change line 3 (or so): set -e to set -x, save the file. (option -e is "exit on errors", -x means "explicitly show command executed", presumably)

Run sudo dpkg --configure -a --log /tmp/dpkg.log (the --log option is optional). You can also simply run apt upgrade if you know it'll be the only package that will be upgraded.

Now you get verbose output of the mysql-server-5.7.postinst bash script, and you can figure out what's wrong.

In my case it unsuccessfully tried to (re-)run mysql_upgrade, but that was not needed for my customized mysql installation. I was sure I've run it manually before, successfully, and all was well.

So I commmented out line 321 (for older mysqld releases try line 281),

#mysql_upgrade --defaults-file=/etc/mysql/debian.cnf || result=$?

and the command that has failed before, sudo apt upgrade (run it again), finished successfully, and dpkg removed the error status for this package.

Now you can set back the set -x to set -e (mentioned above). And optionally uncomment the mysql-upgrade line.

Extra work might be required if you have moved your mysql data partition to a nonstandard location. I moved mine from /var/lib/mysql/data to a different drive via symlink. Then you might have to remove the symbolic link temporarily, before the postinst script manipulation. Then re-create it after running the package upgrade.

After the next minor version upgrade of the mysqld debian package, this problem with the /var/lib/dpkg/info/mysql-server-5.7.postinst script can show up again.