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:
-
Back up your
my.cnf file
in/etc/mysql
and remove or rename itsudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
-
Remove the folder
/etc/mysql/mysql.conf.d/
usingsudo rm -r /etc/mysql/mysql.conf.d/
-
Verify you don't have a
my.cnf
file stashed somewhere else (I did in my home dir!) or in/etc/alternatives/my.cnf
usesudo find / -name my.cnf
-
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
-
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.
The instructions here fixed it on my server: https://bugs.mysql.com/bug.php?id=72722
I can understand the pain of having your system in inconsistent state but lets not worry about the whole situation and take it step by step to get the system clean.
First lets see the current state of all the mysql packages on machine using: dpkg -l | grep mysql (Please paste the output excluding last column)
The first column denotes the current status of the package. Here are the possible options:
ii) Installed rc) Removed config-files kept (This should be the state of all the packages you have removed with 'apt-get remove' that does not remove config-files under /etc)
For this to work, you will need to run 'apt-get purge <pkg-name>' till you do not see any packages in the above list.
Please remember that some non-mysql-server packages like python-mysql.connector and python-mysqldb, if installed, need not be removed as they do not have any affect on this situation but if removed might cause trouble to applications using them.
We will definitely try to re-visit our docs to see how can we safeguard users from getting into this trouble. Thanks for sharing your feedback in detail with us.
In my case, with strace, I saw that /var/run/mysqld/ didn't exist and mysqld can't create the file mysqld.sock.
These commands solved my problem:
mkdir /var/run/mysqld
chown mysql.mysql /var/run/mysqld
chmod 700 /var/run/mysqld
Now:
systemctl start mysql
And mysql works again :)