MySQL-server installation does not complete

I finally was able to solve the problem by removing all the dependencies and configuration files of the mysql as well as maria-db first. To do that, go to /var/lib and delete all the files related to mysql (You will have to have root permissions to delete them so dont forget to write sudo su before that). You can delete all the files by typing rm -r /var/lib/mysql*.
After that you have to delete all the files in the /etc directory by typing rm -r /etc/mysql*

Then perform the following commands and you will be set to go :

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

Try these. Hope it helps.

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql* 
sudo apt-get autoremove 
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade
sudo apt-get install mysql-server