dpkg: error processing package mysql-server (dependency problems)?
All of the answers I've been able to find for this question have been of the form "purge your Mysql install and re-install it." But in my case, I already have a working/active Mysql install. For me, the reason why dpkg --configure -a
fails is because Mysql is already installed. Why dpkg thinks that the postinstall script needs to be run for my already-installed-and-upgraded Mysql I may never know, but it does.
After considerable time scouring for answers, I found a solution that should work if there are others who already have a working Mysql 5.7 and just want to get past this bogus postinstall script. You can edit the postinstall script directly as (on Ubuntu):
sudo vi /var/lib/dpkg/info/mysql-server-5.7.postinst
And then, on the second line, just add exit 0
and then run dpkg
again and you should get something like:
$ sudo dpkg --configure -a
Setting up mysql-server-5.7 (5.7.28-0ubuntu0.18.04.4) ...
You definitely would not want to follow these instructions if your Mysql installation had not previously completed (there's a reason that the postinstall script insists on running). But for those who might end up with dpkg in a wonky state, as I have, the above can save you a lot of time purging and reinstalling an already-working version of Mysql.
dpkg
returning an error code 1 doesn't mean anything specific but it usually has to do with dependency issues. In your case, you tried to install two versions/instances of the same package i.e. mysql-server
and mysql-server-5.7
. So do the following to remove any redundant dependency issues and install a functioning mysql package
sudo apt-get clean
sudo apt-get purge mysql*
sudo apt-get update
sudo apt-get install -f
sudo apt-get install mysql-server-5.7
sudo apt-get dist-upgrade
this should fix the problem at hand. But in the future, have care about the package names you add after sudo apt-get install
since the wrong list of package names - for example redundant entries in the list - results in failure to install either of the packages or worse - you might even find yourself wading through the hellish depths of #DEPENDENCY-HELL