dpkg: error processing package mysql-server (dependency problems)?
Asked Answered
K

19

42

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?

Kindness answered 17/4, 2017 at 6:22 Comment(0)
R
71

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
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

Reasoning answered 29/6, 2017 at 10:8 Comment(3)
I like how you run apt clean before all else, this should be evangelized. Too many tutorials say to purge packages, apt update or force install, or etc and then run apt autoclean afterwards, which is sometimes pointless (backwards and/or less effective) because the package cache should be emptied out BEFORE proceeding with reinstall, etc...Concinnate
sudo apt-get install mysql-server-5.7 should be done by sudo apt-get install -f, shouldn't it? Was the case on my machine at least.Olpe
If server is low on RAM, please see VPS answer further down. (Running mysql + apt upgrade => mysql crash)Foramen
C
27

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.

Creamery answered 6/1, 2020 at 19:44 Comment(4)
This solved the issue for me, thanks! I had ssh crash mid upgrade and like a dummy wasn't using screen. So when I logged back in, the post install didn't want to work.Pagas
It seems the original question (error message) is a general one. For me, this answer is the one that solved the problem. Cleaning up everything and reinstalling does not solve my problem, and introduces additional task of restoring the database.Cinchona
This solved the problem for me too.Philately
Yeah, this was the solution for me!Matronize
B
16

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
Befuddle answered 28/6, 2017 at 22:18 Comment(0)
F
9

If you're on a VPS or similar, your error may be due to lack of RAM.

Running apt-upgrade seems to require some RAM, so it may force-close mysql, hence the problem to recover from the error.

Try:

1) Stop mysql manually before any apt-upgrade

sudo /etc/init.d/mysql stop

2) Fix:

sudo dpkg --configure mysql-server-X.X

(if version not known, use just mysql-server to find out (will not fix error)

3) Check:

sudo apt-get upgrade

Start mysql manually if it wasn't started by apt.

Foramen answered 19/5, 2018 at 6:37 Comment(1)
You right. i used VPN 1.5 GB ram in Google cloud Compute is work. but not with free tier < 1 GBPickar
E
5

i face same error due to problem in my upgrade from ubuntu 18.04 to ubuntu 20.04 , what i did is get mariadb instead also make sure when you do pruge mysql that if asked you to remove dbs in the dir tell it not to delete the dbs so you will have your old databases with no data loss

what i did was this cmds

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get dist-upgrade
sudo apt-get install mariadb-server
Enlarge answered 20/10, 2020 at 16:17 Comment(0)
R
4

My answer from askubuntu.

New Answer

kill the musql deamon and purging helps

sudo pkill mysqld # kill
sudo apt-get purge mysql-server-5.7 # Or whatever you are trying to purge.

Thanks, @endrias for the suggestion.

Old Answer

None of the apt methods worked for me, try this:

Find locking process

$ ps -eaf
root      7316     1  0 00:19 ?        00:00:00 /usr/bin/dpkg --status-fd 35 --configure --pending
root      7808  7316  0 00:19 ?        00:00:00 /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/mysql-se
root      7817  7808  0 00:19 ?        00:00:00 /bin/bash /var/lib/dpkg/info/mysql-server-5.7.postinst configure
mysql     7973  7817  0 00:20 ?        00:00:00 mysqld --user=mysql --init-file=/var/lib/mysql-files/tmp.iNyY06ty0K --so

Kill it

do sudo kill -9 7973, basically the mysql one.

Now purge

sudo apt-get purge mysql-server-5.7 # Or whatever you are trying to purge.
Ronel answered 18/10, 2018 at 4:35 Comment(1)
if a running mysql process is preventing any fixes, you can use sudo pkill mysql to kill the mysql daemon instead of going the roundabout way of getting the PID from the output of ps -eaf, pkill does the PID getting for you.Reasoning
C
4

I had a similar issue. This is how I fixed mine.

  1. Restart MySQL service sudo service mysql restart
  2. Then fix broken installations sudo apt install -f
Cristacristabel answered 25/10, 2018 at 8:26 Comment(0)
D
2

I tried almost every possible way but nothing was working for me. Then I found the problem that I was facing was due to less available ram. You can check your current ram status by free -h (in my case available was less than 1 GB). To clear ram restart your device. Then type following commands

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

then again install mysql-server by

sudo apt-get install mysql-server
Dilks answered 31/8, 2020 at 16:40 Comment(0)
S
1

try this solution using aptitude this will replace all the file corrupted.

This is work on my 18.04

cr. https://www.digitalocean.com/community/questions/mysql-installation-error-dpkg-error-processing-package-mysql-server-5-5-configure?answer=61604

Serf answered 7/12, 2020 at 9:7 Comment(0)
D
1

In my case I had to run:

systemctl stop mysql.service

to stop MySQL before being able to install mysql without errors using:

sudo apt-get install mysql-server
Deer answered 2/2, 2021 at 11:4 Comment(0)
H
0

To solve the dependency issue, try:

sudo apt-get purge
sudo apt-get clean
sudo apt-get check

And reinstall the package again by: sudo apt-get install mysql-server.

Source: Thread: Dpkg: Dependency problems - leaving unconfigured.

Other commands to try:

sudo apt-get install -f
sudo apt-get autoremove
sudo dpkg --configure -a 

Related: How can I Resolve dpkg dependency? at Ask Ubuntu.

Heuristic answered 27/10, 2017 at 23:19 Comment(0)
B
0

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

Breakout answered 14/9, 2018 at 10:35 Comment(0)
P
0

If you are working on Debian 10, you need to first install GNUPG:

sudo apt-get install gnupg

That's all; now you can try dpkg again.

Plural answered 10/2, 2020 at 21:37 Comment(0)
D
0

Also pay attention to the terminal you are using, if it is ZSH many uninstall commands will not work like: sudo apt-get purge mysql* and the reinstallation process will fail, to fix this it is simple type in your terminal the word bash so that the terminal used is Bash, run the sudo apt-get purge mysql* command again and also the following commands below to confirm that you removed everything.

sudo apt-get remove mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

Finally, run mysql --version to make sure there is no version on your machine and you can try installing again.

Drucilladrucy answered 7/12, 2021 at 18:58 Comment(0)
Z
0

I came across the yes Unix binary, which is incredibly stupid: it just endlessly types y (try it, you can just run yes in your terminal)

so the following just works (I used this in a dockerfile)

yes | apt-get install mysql-community-server
Zsolway answered 16/8, 2022 at 8:26 Comment(0)
J
0

I had another mysql process running in background. (ckeck if your lampp mysql server is on, Then turn it off.) then try sudo apt dist-upgrade

if lammp mysql is not working then, check this command, ps -eaf and then look for mysql process and kill it by it's port number sudo kill -9

Jinny answered 14/9, 2022 at 7:30 Comment(0)
E
0

Nothing above worked for me with mysql 8.0. So I followed this:

# Kill the server
sudo pkill mysqld

# Clear the files
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

# Purge and flush out any trash
sudo apt-get purge mysql-server mysql-server-8.0 mysql-common mysql-server-core-8.0
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get update
sudo apt-get install mysql-server

# Restart the server
sudo systemctl start mysql
sudo systemctl status MySQL

Eurystheus answered 11/7 at 19:14 Comment(0)
P
-1

I was in the same situation. After completely removing MySQL, I reinstalled it, killed the PID using port 3306, and reinstalled MySQL again. It's working now.

screenshot

Phane answered 26/11, 2019 at 15:50 Comment(0)
J
-1

1.Check for Dependencies:

Ensure that all dependencies required by MySQL Server are installed. You can use the following command to install any missing dependencies:

sudo apt-get install -f

2.Purge Existing MySQL Packages:

Try purging the existing MySQL packages before attempting a fresh installation. Note that this will remove MySQL and its configuration files:

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

3.Remove Configuration Files:

After purging, make sure to remove the MySQL configuration files:

4.Update Package Lists: Ensure that your package lists are up to date:

sudo apt-get update

5.Install MySQL Server: After purging, try installing MySQL Server again:

sudo apt-get install mysql-server

6.Configure MySQL Server: During the installation, you might be prompted to set a root password and configure other settings. Follow the prompts to complete the installation.

7.Check for Specific Errors:

Examine the detailed error messages during the installation process. These messages can provide insights into the specific issues.

8.Manually Remove Lock Files:

Remove any existing lock files that might be causing issues:

sudo rm /var/lib/dpkg/lock
sudo rm /var/cache/apt/archives/lock

After trying these steps, attempt to install MySQL Server again. If you encounter any specific error messages, please provide those details, and I can offer more targeted assistance.

Joaquin answered 5/1 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.