Unable to install or remove MySQL

Solution 1:

I think the fact that you had MariaDB installed caused this problem. The configs that MariaDB set up do not exactly play nice with vanilla MySQL. If you were to purge all of the old configs and set everything up from scratch, it should work. Note though that this will delete your current DBs! Back up any important data.

Try running the following command to reset and purge all MySQL related things:

sudo apt purge mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 mysql-server

Once this is done, run the below to update your system and "clean up" your package cache.

sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt -f install

Then, try re-installing MySQL Server:

sudo apt install mysql-server

Solution 2:

This error can occur when you install mariadb-server before mysql-server. To resolve this error, you must delete directories /var/lib/mysql* and /etc/mysql* to remove all configurations and dependencies files, before trying to install MySQL again.

sudo apt purge mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7 mysql-server
sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt -f install
sudo apt install mysql-server