3

Recently I tried to install the package mysql-server-8.0 on my computer, using Ubuntu 20.04. I had some issues and decided to completely un- and reinstall mysql again.

So, if I try to uninstall it through sudo apt-get remove mysql-server-8.0, I'll get the following output:

sudo apt-get remove mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-image-5.4.0-54-generic linux-modules-5.4.0-54-generic linux-modules-extra-5.4.0-54-generic mecab-ipadic mecab-ipadic-utf8 mecab-utils python3-imdbpy
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mysql-server-8.0
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 1465 kB disk space will be freed.
Do you want to continue? [Y/n] y
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)

The output suggests to re-install the package, so I tried this:

sudo apt install --reinstall mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-image-5.4.0-54-generic linux-modules-5.4.0-54-generic linux-modules-extra-5.4.0-54-generic python3-imdbpy
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  mailx tinyca
The following packages will be upgraded:
  mysql-server-8.0
1 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
Need to get 0 B/1261 kB of archives.
After this operation, 1024 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 751683 files and directories currently installed.)
Preparing to unpack .../mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_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 /var/cache/apt/archives/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb (--unpack):
 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:
 /var/cache/apt/archives/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

The interesting part here is this line:

Failed to stop mysql.service: Unit mysql.service not loaded.

There is no mysql service running:

systemctl status mysql
Unit mysql.service could not be found.

It seems like it fails because there is no mysql service running. I can't start one neither.

systemctl start mysql 
Failed to start mysql.service: Unit mysql.service not found.

Now I am stuck here and wasn't able to un-/reinstall mysql again. I also tried removing the package with synaptic and with sudo dpkg --purge --force-all mysql-server-8.0, which I found on the internet. They all output a message telling me the package is in a bad state.

dpkg -l | egrep -v '^ii|rc' gives the following output:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
+++-===========================================================-==========================================================-============-======================================================================================================
it  desktop-file-utils                                          0.24+linuxmint1                                            amd64        Utilities for .desktop files
it  gnome-menus                                                 3.36.0-1ubuntu1                                            amd64        GNOME implementation of the freedesktop menu specification
it  hicolor-icon-theme                                          0.17-2                                                     all          default fallback theme for FreeDesktop.org icon themes
it  man-db                                                      2.9.1-1                                                    amd64        tools for reading manual pages
it  mime-support                                                3.64ubuntu1                                                all          MIME files 'mime.types' & 'mailcap', and support programs
pU  mysql-client-8.0                                            8.0.22-0ubuntu0.20.04.3                                    amd64        MySQL database client binaries
pi  mysql-common                                                5.8+1.0.5ubuntu2                                           all          MySQL database common files, e.g. /etc/mysql/my.cnf
rFR mysql-server-8.0                                            8.0.22-0ubuntu0.20.04.2                                    amd64        MySQL database server binaries and system database setup
it  shared-mime-info                                            1.15-1                                                     amd64        FreeDesktop.org shared MIME database and spec
iU  xserver-common                                              2:1.20.8-2ubuntu2.6                                        all          common files used by various X servers
iU  xserver-xephyr                                              2:1.20.8-2ubuntu2.6                                        amd64        nested X server
iU  xserver-xorg-core                                           2:1.20.8-2ubuntu2.6                                        amd64        Xorg X server - core server
iU  xserver-xorg-legacy                                         2:1.20.8-2ubuntu2.6                                        amd64        setuid root Xorg server wrapper
iU  xwayland                                                    2:1.20.8-2ubuntu2.6                                        amd64        Xwayland X server

ls -al /etc/init.d/ | grep mysql gives:

-rwxr-xr-x   1 root root  5607 Nov  6  2019 mysql
4
  • Please , show dpkg -l | egrep -v '^ii|rc'
    – nobody
    Dec 2, 2020 at 11:58
  • I have added the output to the question. :)
    – KiraTM
    Dec 2, 2020 at 16:25
  • Oh your problem is bigger as I thought. Make first a backup from your important data.
    – nobody
    Dec 2, 2020 at 16:31
  • Alright, thank you. What do I have to do then?
    – KiraTM
    Dec 2, 2020 at 17:30

4 Answers 4

1
wget -c http://security.ubuntu.com/ubuntu/pool/main/m/mysql-8.0/mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb

Install the package direct with dpkg.

sudo dpkg -i mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb

Only when no errors.

software-properties-gtk

and choose to download from main server.

sudo apt update && sudo dpkg --configure -a && sudo apt -f install

Then update your System.

sudo apt full-upgrade
5
  • I get the same error message as in the question when I run "sudo dpkg -i mysql-server-8.0_8.0.22-0ubuntu0.20.04.3_amd64.deb". :/ It fails again to stop the mysql service.
    – KiraTM
    Dec 3, 2020 at 16:10
  • ls -al /etc/init.d/ | grep mysql please @KiraTM
    – nobody
    Dec 3, 2020 at 17:27
  • I have added the result to the question.
    – KiraTM
    Dec 3, 2020 at 18:23
  • service status mysql try to start it if it is not running. sudo service mysql --full-restart
    – nobody
    Dec 3, 2020 at 21:17
  • Those commands give me "status: unrecognized service" and "Failed to restart mysql.service: Unit mysql.service not found."
    – KiraTM
    Dec 3, 2020 at 22:13
1

I managed to fix my specific issue even though it probably wasn't the cleanest way to do it. Since the removal script failed due to the mysql service not being existant, I tried the following:

  1. Navigate to /var/lib/dpkg/info/

  2. Opened the file mysql-server-8.0-prerm as root (for exaple with gedit), this is the pre-removal script

  3. I have commented the lines which tried to stop the service:

    #if [ -x "/etc/init.d/mysql" ]; then #invoke-rc.d mysql stop || exit 1 #fi

  4. Then I ran sudo dpkg --purge --force-all mysql-server-8.0

  5. This gave a few warnings, but the --force switch forced the package to uninstall nonetheless

  6. After the package being removed, I now had one corrupt package installed (mysql-client-8.0) which I could remove using the GUI of Synaptic Package Manager (apt-get remove would have probably worked too)

This fixed the issue at least for me and I can install other packages again. It was impossible to install new packages even if they didn't need mysql due to the unstable status.

Thank you very much to all who tried to help me here. I'm sorry that you have wasted your time with me, but maybe someone else finds your answers helpful!

0

To remove MySQL, first run the command:

sudo apt remove -y mysql-*

and then:

sudo apt purge -y mysql-*

Now, to install mysql again, update package list and use the command

sudo apt update
sudo apt install mysql-server
1
  • Thanks for the answer. Unfortunately, this didn't work. :( The output was "E: Unable to locate package mysql-*" Packages beginning with mysql- were mysql-server-core-8.0, mysql-client-core-8.0 and mysql-common. I got the same issue as in the question above when removing them one by one.
    – KiraTM
    Dec 1, 2020 at 22:10
0

Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service/lib /systemd/system/mysql service.

I guess if you create a symlink to that file it will fix it, I had this bug myself I did what the previous guy did the purged everything MySQL related except for mysql-common (that will uninstall half your OS if you get rid of that).

And noticed the symlink creation when reinstalling.

Might save some people from headbutting the desk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .