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
dpkg -l | egrep -v '^ii|rc'