Score:-2

mysql-server-8.0 error blocking apt installations

gb flag

I tried to update Ubuntu 20.04 after a long while, and it failed due to some MySQL error. I searched the web and the suggested answer was rm mysql directories. I did that, but it still did not solve the problem.

I tried dpkg --remove --force-all mysql-server-8.0, but it says:

Unit mysql.service could not be found. dpkg: error while cleaning up:  
...post-installation script subprocess returned error

apt purge/upgrade/remove fails with

The package mysql-server-8.0 needs to be reinstalled

I don't remember installing MySQL, but even if I did, I don't need MySQL. I don't care about it at all. How can I completely nuke MySQL and get apt working again?

test@ubuntu:~$ sudo apt install --reinstall mysql-server-8.0 
Reading package lists... Done 
Building dependency tree
Reading state information... Done
E: The package mysql-server-8.0 needs to be reinstalled, but an archive for it can't be found.
test@ubuntu: $ sudo apt purge mysql-server-8.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: The package mysql-server-8.0 needs to be reinstalled, but an archive for it can't be found.
test@ubuntu:~$ sudo apt install mysql-server --reinstall
Reading state information... Done
Reading package lists... Done 
Building dependency tree 
E: The package mysql-server-8.0 needs to be reinstalled, but an archive for it can't be found. 

~$ sudo apt purge mysql-server-core-8.0 -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
  libhtml-template-perl libllvm10 libllvm11 libmecab2 libreadline5
  libterm-readkey-perl linux-headers-5.4.0-42 linux-headers-5.4.0-42-generic
  linux-image-5.4.0-42-generic linux-modules-5.4.0-42-generic
  linux-modules-extra-5.4.0-42-generic mecab-ipadic mecab-ipadic-utf8
  mecab-utils socat
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED
  mysql-server-8.0* mysql-server-core-8.0*
0 to upgrade, 0 to newly install, 2 to remove and 3 not to upgrade.
1 not fully installed or removed.
After this operation, 137 MB disk space will be freed.
Do you want to continue? [Y/n] 
dpkg: error processing package mysql-server-8.0 (--remove):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting a removal
dpkg: too many errors, stopping
Errors were encountered while processing:
 mysql-server-8.0
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

and

$ sudo dpkg -i --force-all mysql-server-8.0_8.0.27-0ubuntu0.20.04.1_amd64.deb
(Reading database ... 471728 files and directories currently installed.)
Preparing to unpack mysql-server-8.0_8.0.27-0ubuntu0.20.04.1_amd64.deb ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: warning: old mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
dpkg: error processing archive mysql-server-8.0_8.0.27-0ubuntu0.20.04.1_amd64.deb (--install):
 new 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_8.0.27-0ubuntu0.20.04.1_amd64.deb
uz flag
Jos
The remove fails because the installation is now incomplete. One trick may be to do `sudo apt install mysql-server-8.0 --reinstall` and then `sudo apt remove mysql-server-8.0` will succeed.
uz flag
Jos
What about `sudo apt install mysql-server --reinstall`?
Damn Vegetables avatar
gb flag
@Jos apt install (including --reinstall) fails with "The package mysql-server-8.0 needs to be reinstalled".
Damn Vegetables avatar
gb flag
@Jos Please see the appended screenshot.
uz flag
Jos
No, I deliberately left out the `-8.0` part in my comment. It may make a difference.
Damn Vegetables avatar
gb flag
@Jobs Please see the newly appended screenshot. The same result. Well, I guess that I have no choice but to reinstall Ubuntu. I really think that Ubuntu needs to add some sort of automated fixing utility for important part of the OS, even if it is due to the user's misconfiguration or something. Windows has lots of "troubleshoot" wizards that detects some common problems of the OS and resets it.
Vthechamp avatar
jp flag
`sudo apt install -f`?
Damn Vegetables avatar
gb flag
@Vthechamp `-f` does not seem to change the response.
Vthechamp avatar
jp flag
I had a similar sort of error for mysql 8, i think i fixed it by restarting my system, maybe you could try that?
mchid avatar
bo flag
Does this answer your question? [E: The package needs to be reinstalled, but I can't find an archive for it](https://askubuntu.com/questions/147178/e-the-package-needs-to-be-reinstalled-but-i-cant-find-an-archive-for-it)
Score:1
my flag

If you cannot find an archive for Mysql then try manually installing the archive.

First, Try if downloading the deb file works:

sudo apt download mysql-server-8.0

Now, using dpkg compile the archive:

sudo dpkg -i --force-all ./*.deb

If the above didn't work then try:

First, click here, and a deb file will start downloading.

After that use the dpkg -i command to install the .deb file.

I am not sure but you can also run the following command to download the deb and install it:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb && sudo dpkg -i *.deb

After, running the above:

sudo apt install mysql-server-8.0

If the above didn't work then purge MySQL:

sudo dpkg -P mysql*

Here is another way to remove MySQL:

sudo mv /var/lib/dpkg/info/mysql* ~/ && sudo apt -f install

If the above all didn't work then one last thing to try is:

First, change the contents of /etc/apt/sources.list to:

deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner

And run apt update followed by:

sudo apt download mysql-server-8.0
sudo dpkg -i --force-all ./*.deb

If that also didn't worked then

If the above didn't work then I'll recommend reinstalling Ubuntu.

Damn Vegetables avatar
gb flag
I have appended the output the the question. `sudo dpkg -P mysql*` fails with "dpkg: error: you must specify packages by their own names, not by quoting the names of the files they come in...." I guess `*` does not work.
Damn Vegetables avatar
gb flag
Oh well, I guess it will be faster just to reinstall Ubuntu and reconfigure it from scratch. Thank you for all your support. I marked this as an answer, because this will help future people with similar problems.
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.