Cannot reinstall mysql

I have been having problems with Owncloud after upgrading my server to 18.04 so I decided to try Nextcloud with Mariadb following these instructions The command "sudo systemctl start mariadb" kept timing out so I gave up and decided to try again with Owncloud and mysql. But then whenever I tried to use "sudo mysql -u root -p" I got the message

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 

I discovered this was probably to do with Mariabd and so completely purged both mysql and Mariadb. Now when I try and re-install mysql I get the following message and after installation cannot log in to mysql

Configuring mysql-server-5.7 Automatic maintenance of MySQL server daemon disabled
Packaging maintainer scripts detected a case that it does not know how to handle and cannot continue configuring MySQL. Automatic management of your MySQL installation has been disabled to allow other packaging tasks to complete. For more details, see /etc/mysql/FROZEN.

The contents of etc/mysql/FROZEN read:

his MySQL or variant installation has entered "frozen mode". Maintainer scripts will avoid making changes or starting the daemon until manually released from this state. See /usr/share/doc/mysql-common/README for general information about this mode.

In this particular case, an incompatible downgrade attempt has been detected. This can be resolved in one of two ways:

  1. Change the contents of /var/lib/mysql/ to contain database data that is compatible with the currently installed MySQL or variant daemon version. For example: you could restore from a backup. Alternatively you could do a dump using a future version binary and then a restore using the current version binary.

  2. Switch to a MySQL or variant daemon version that is compatible with the data currently in /var/lib/mysql/. For example, if you have attempted a downgrade from mysql-server-5.7 to mysql-server-5.6, you could "apt install mysql-server-5.7" again.

I renamed the three files there that had to do with mysql and purged mysql again and tried another install, only to get the same message again.


Solution 1:

Fixed it! The problem was the file /etc/mysql which wasn't being removed by purge. I renamed it with mv and then installed mysql-server and now I can log into mysql.