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.
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.
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:
- Remove the post installation script of the package:
sudo rm /var/lib/dpkg/info/mysql-server-8.0.postinst
- 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