Ubuntu – How to completely uninstall thesql-server and reinstall

MySQLserveruninstall

I recently upgraded from 12.10 to 16.04 on my server. After upgrading (which appears to have gone fine), I was unable to login to my mysql server. As such, I uninstalled the server, and reinstalled using:

apt-get remove mysql-server
apt-get install mysql-server

However, now it always seems to give me:

Renaming removed key_buffer and myisam-recover options (if present)
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
insserv: warning: script 'screen-cleanup' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `screen-cleanup'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `screen-cleanup'
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up mysql-client (5.7.16-0ubuntu0.16.04.1) ...
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Processing triggers for systemd (229-4ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19) ...
Errors were encountered while processing:
 mysql-server-5.7
 mysql-server

I tried stopping the service, uninstalling, purging, and even removing /etc/mysql and /var/lib/mysql (after backing up, of course).

I'm at a complete loss as to why this is happening now. I can't seem to recover my database data. I've noticed that whenever I do this uninstall/reinstall procedure, it's not asking me for a mysql password, so I wonder if it's not completely uninstalled.

Best Answer

To remove all config files use

apt-get purge mysql-server\*
rm -rf /etc/my.cnf /etc/mysql

If you want to delete all databases as well, you need to delete the directory /var/lib/mysql, too.