Score:2

Cannot remove mysql-server-8.0 on Ubuntu 20.04

tm flag

after dist upgrading Ubuntu to Ubuntu 20.04 mysql does not work. I tried to remove it and my goal is to reinstall it. The problem is that I can not remove mysql-server-8.0:

sudo dpkg -r --force-all mysql-server-8.0
(Reading database ... 210243 files and directories currently installed.)
Removing mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing package mysql-server-8.0 (--remove):
 installed mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error while cleaning up:
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 mysql-server-8.0
openhabvm@OpenHABVM:~$ sudo dpkg -r --force-all mysql-server-8.0
(Reading database ... 210243 files and directories currently installed.)
Removing mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing package mysql-server-8.0 (--remove):
 installed mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action "start" failed.
Unit mysql.service could not be found.
dpkg: error while cleaning up:
 installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 mysql-server-8.0
Someone avatar
my flag
Try running `sudo dpkg -P --force-all mysql-server-8.0`
Score:0
my flag

The error message suggests that the post-installation script of the package tried to enable the service file of MySQL but found that it's already off. You can try removing it as follows:

sudo service mysqld start
sudo dpkg -r --force-all mysql-server-8.0

If this throws the same error then follow one of the following methods.

For forcefully purging the package.

  1. Since removing packages can be destructive, print the list of the package that will be removed:

    dpkg -l | awk  '{print $2}' | grep -i mysql | grep -v lib
    

    Check if any important package is being removed. If everything seems fine, proceed to step 2.

  2. Purge the packages:

    sudo dpkg -P  --force-all $(dpkg -l | awk  '{print $2}' | grep -i mysql | grep -v lib)
    

This should completely remove MySQL. Then run a force install:

sudo apt -f install

If the above failed with the same error then follow these steps:

  1. Remove the post installation script of the package:
    sudo rm /var/lib/dpkg/info/mysql-server-8.0.postinst
    
  2. Purge the packages:
    sudo dpkg -P  --force-all $(dpkg -l | awk  '{print $2}' | grep -i mysql | grep -v lib)
    

Run a force-install:

sudo apt -f install

After purging the package, to reinstall it run:

sudo apt update
sudo apt install mysql-server-8.0
Score:0
ml flag

I had the same problem (i.e. unable to install either mariadb-server or mysql-server) after I switched from Ubuntu 20.04 to 22.04 and was able to solve it by deleting the following and then repeating the install process:

  1. sudo rm /var/lib/dpkg/info/mysql-server-8.0.postinst
  2. sudo rm /var/lib/dpkg/info/mysql-server-8.0.preinst
  3. sudo rm /var/lib/dpkg/info/mysql-server-8.0.prerm

Try this and see if it works for you.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.