dpkg: error processing package mysql-server

2020-07-03 03:39发布

When I try to install mysql-server, an error comes like:

dpkg: error processing package mysql-server (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

What does it mean. Any ideas?

10条回答
ゆ 、 Hurt°
2楼-- · 2020-07-03 04:21

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-07-03 04:24

This should help

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade

And now reinstall mysql

sudo apt-get install mysql-server
查看更多
beautiful°
4楼-- · 2020-07-03 04:28

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

查看更多
混吃等死
5楼-- · 2020-07-03 04:30

The problem can be much simpler (in my case) I had a missconfigured value in my configuration file [my.cnf] which lead to the error. After cleaning up my.cnf mysql-server was restarted successfully

查看更多
登录 后发表回答