How do I completely remove mysql-server on Debian?

I figured I'd share my question here and then answer, as there seems to be many people stuck in my position - but no definitive answer. The problem is, if you apt-get remove mysql-server, it does not clean up the configuration and database files, so if you've somehow screwed them up, then installing again, will not replace them. So there seems to be many people asking "how do I completely remove mysql-server, so that I can re-install a fresh?" -- everyone answers with apt-get remove --purge mysql-server -- I'm not sure why, but this does not fully uninstall. My answer follows...


Solution 1:

removing mysql-server does not work because mysql-server is just a metapackage that depends on the specific server version

apt-get remove --purge 'mysql-.*'

or

apt-get remove --purge 'mysql-server.*'

will do the trick.

Solution 2:

This worked for me (I'd also tried installing v5.0, but this made matters worse):

apt-get remove --purge mysql-server-5.0 mysql-common mysql-client-5.0 \
mysql-server-5.1 mysql-client-5.1 mysql-server mysql-client

apt-get install mysql-server

I think the key here is removing mysql-common -- but I'm not sure. Please try this and leave your comments.