Can't install mysql-server/client on ubuntu 16

Solution 1:

We execute the following commands to solve the above problem:

  1. Get the list of MySQL packages installed on the system by executing the command sudo dpkg -l | grep mysql
  2. Remove the the packages shown above by executing the command sudo apt-get --purge autoremove <packages from the step 1>
  3. Delete /var/lib/mysql
  4. Try to install mysql again. It should solve your problem.

Solution 2:

I have no idea why, I tried around with these commands for like an hour untill I just made

export TERM=xterm

and then it just worked with apt install.

EDIT: Actually now I know why. It might be that during the installation it's trying to bring up the visual interface asking "install the package maintainter's version" and similar, and the default TERM on some Ubuntu servers is not able to serve that, so the installation throws an error. Xterm use solves that problem.