How to repair corrupt package installation (mysql)

Do the following to clean out the broken packages:

sudo apt-get clean
sudo apt-get update
sudo dpkg -r mysql-client-5.7
sudo dpkg -r mysql-server-5.7
sudo dpkg -r libmysqlclient20:i386
sudo dpkg -r libmysqlclient20:amd64
sudo dpkg -r libmysqlclient18:amd64
sudo dpkg -r mysql-common
sudo dpkg -r mysql 

After that reinstall it with:

sudo apt-get install mysql mysql-client* mysql-server*

Thanks to @Videonauth

sudo dpkg -r mysql-client-5.7
sudo dpkg -r mysql-server-5.7
sudo dpkg -r libmysqlclient20:i386
sudo dpkg -r libmysqlclient20:amd64
sudo dpkg -r libmysqlclient18:amd64
sudo dpkg -r mysql-common

Then running:

sudo apt-get purge mysql\* mariadb\* libmysql\* libmariadb\*

If anything fails, just run sudo dpkg -r <failedpackage> and if THAT fails just remove the package that is dependent on it. If you repeat, eventually apt-get will work again.

See also What is the difference between dpkg and aptitude/apt-get?


Try this,

run this command to purge mysql, replace version 5.7 with your installed version

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

run this to clean up and update packages

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

finally install mysql

sudo apt install mysql-server

this worked for me.