21

After upgrading to Ubuntu 16.04, I noticed mysql was having mind-boggling errors. Convinced, it was a broken setup, I tried running a purge of mysql. That didn't seem to delete everything, so I tried doing it myself:

sudo rm -r /etc/mysql
sudo rm -r /usr/share/mysql-workbench
sudo rm -r /usr/share/mysql
sudo rm -r /usr/share/mysql-common

This was a mistake. Don't EVER try to do this. Now mysql won't even install correctly. I've tried reinstalling the dependancies:

sudo apt-get install --reinstall $(apt-cache depends mysql-server | grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ' )

And the packages themselves:

sudo apt install mysql-workbench mysql-server --reinstall

But I get all sorts of cryptic errors, such as:

sudo apt-get install --reinstall mysql-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not         upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for mysql-server:amd64

And uninstalling

sudo apt-get remove mysql-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libmysqlclient20 : Depends: mysql-common (>= 5.5) but it is not going to be installed
 mariadb-client-core-10.0 : Depends: mariadb-common (>= 10.0.24-7) but it is not going to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

Or if I reconfigure

sudo dpkg --configure -a
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
/var/lib/dpkg/info/mysql-server-5.7.postinst: line 112: /usr/share/mysql-common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server

Or if I Force install:

sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
/var/lib/dpkg/info/mysql-server-5.7.postinst: line 112: /usr/share/mysql-common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

Or if I do a purge:

sudo apt-get -f purge mysql-server 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  mysql-server*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 159 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 348226 files and directories currently installed.)
Removing mysql-server (5.7.12-0ubuntu1) ...
Setting up mysql-server-5.7 (5.7.12-0ubuntu1) ...
/var/lib/dpkg/info/mysql-server-5.7.postinst: line 112: /usr/share/mysql-common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 mysql-server-5.7
E: Sub-process /usr/bin/dpkg returned an error code (1)

Is apt unable to recover from a partial install? Do I have to reinstall the OS??

Jonathan
  • 3,904

10 Answers10

31

Do the following to clean out the broken packages:

sudo apt-get clean
sudo apt-get update
sudo dpkg -r mysql-client-5.7
sudo dpkg -r mysql-server-5.7
sudo dpkg -r libmysqlclient20:i386
sudo dpkg -r libmysqlclient20:amd64
sudo dpkg -r libmysqlclient18:amd64
sudo dpkg -r mysql-common
sudo dpkg -r mysql 

After that reinstall it with:

sudo apt-get install mysql mysql-client* mysql-server*
Videonauth
  • 33,355
  • 17
  • 105
  • 120
  • thanks a lot!! removing dependencies one by one is the only option to get out of apt-get stuck – stackMonk Nov 27 '17 at 13:23
  • On my ubuntu 18.04 trying to remove mysqlclient ( running 3rd command) produced that : dependency problems prevent removal of mysql-client-5.7: mysql-server-5.7 depends on mysql-client-5.7 (>= 5.7.26-0ubuntu0.18.04.1).

    dpkg: error processing package mysql-client-5.7 (--remove): dependency problems - not removing Errors were encountered while processing: mysql-client-5.7, but running sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7 as from here https://askubuntu.com/questions/760724/16-04-upgrade-broke-mysql-server seems that deleted the instance

    – Carmine May 30 '19 at 21:55
  • now I got a bunch of error as I was trying to install sudo apt install openjdk-8-jre openjdk-8-jdk. – Carmine May 30 '19 at 22:24
  • I was able to find the process that was previously blocking any of my attempt to clean the update of mysql, indeed I stopped an instance running in my system, then I purged as from the other solution linked. After that I made sure my system was update. Indeed I found out somehow I miss many update. After that now so far the installation of java sdk that require itself mysql instance seems proceeded well – Carmine May 31 '19 at 06:22
  • https://www.digitalocean.com/community/questions/mysql-installation-error-dpkg-error-processing-package-mysql-server-5-5-configure – Carmine May 31 '19 at 06:23
17

Thanks to @Videonauth

sudo dpkg -r mysql-client-5.7
sudo dpkg -r mysql-server-5.7
sudo dpkg -r libmysqlclient20:i386
sudo dpkg -r libmysqlclient20:amd64
sudo dpkg -r libmysqlclient18:amd64
sudo dpkg -r mysql-common

Then running:

sudo apt-get purge mysql\* mariadb\* libmysql\* libmariadb\*

If anything fails, just run sudo dpkg -r <failedpackage> and if THAT fails just remove the package that is dependent on it. If you repeat, eventually apt-get will work again.

See also What is the difference between dpkg and aptitude/apt-get?

Jonathan
  • 3,904
  • Removing those libmysqlclient packages, even though other packages rely on them, and purging everything did the trick. Though now I get mysql_upgrade errors. – Jelle De Loecker May 26 '16 at 09:43
  • I never got mysql_upgrade errors. But you may have to remove even more packages. I suppose it depends on which package got corrupted. There's a way to search for all packages installed that are related to mysql but I forget how. I think it's a dpkg list command piped through grep – Jonathan May 30 '16 at 08:49
  • Using fish shell makes it easy to tab complete these dpkg names – Jonathan Sep 07 '20 at 10:07
12

Try this,

run this command to purge mysql, replace version 5.7 with your installed version

sudo apt purge mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 mysql-server

run this to clean up and update packages

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt -f install

finally install mysql

sudo apt install mysql-server

this worked for me.

rahul
  • 233
4

I don't know the exact reason, but all these methods did not work for me. In my case, the procedure that corrected the problem was:

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

sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql*

and reboot!

finally, I have been able to run sudo apt-get install mysql-server!

s1l3n0
  • 141
4

After purging mysql as has been shown above, you have to install mysql this way:

sudo apt-get install mysql-common 
sudo apt-get install mysql-server

When you install this way you will not have an installation error.

d a i s y
  • 5,511
tomek
  • 41
1

I'm also getting these kinds of error and wasted a lot of time. Run these commands

sudo apt-get remove --purge mysql-server
sudo /etc/init.d/mysql stop
sudo apt-get remove --purge mysql-common
sudo rm -rf /var/lib/mysql

sudo apt-get autoremove --purge sudo apt-get autoclean sudo apt-get clean

sudo apt update sudo apt install mysql-server

I found solution on this website Source of the solution

1

This worked for me

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

then after that I installed mysql again with

sudo apt-get install mysql-server and now its working fine.

0

The command sudo dpkg -r does not work for me..

I used sudo apt-get purge mysql-* to uninstall all the releated pageage and then reinstall them

0

This fixed it for me (MySQL 8.0 - Ubuntu 20.04)

sudo apt-get purge mysql\* libmysql\*
sudo apt autoremove

But the package "mysql-client-core-8.0" don't uninstall, so...

sudo apt --fix-broken install
sudo apt-get --reinstall install mysql-client-core-8.0
sudo apt-get purge mysql\* libmysql\*
sudo apt autoremove
sudo apt update
sudo apt install mysql-server

No more errors!

0
  • Check for any broken service link (/etc/systemd/system/mysql.service )
  • Remove any MariaDB stuff (sudo dpkg --get-selections | grep maria)
  • Additional notes at my blog