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...
Asked
Active
Viewed 6.4k times
17

Nick Bolton
- 5,126
- 12
- 54
- 62
4 Answers
25
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.

Justin
- 3,856
- 18
- 21
-
Thanks for the tip. I didn't know wildcards could be used. – Nick Bolton Feb 12 '10 at 02:39
-
it's actually a regular expression, thus the '.*' rather than plain '*'. If you tried to remove mysql-* it would only match a package named like mysql----------- which is not very helpful :-) – Justin Feb 12 '10 at 03:52
-
as mentioned below you'll want to be wary of mysql-common which is used by a few bits and pieces (dovecot springs to mind). – Frenchie Feb 12 '10 at 13:23
-
1Ah, yes, regex not wildcard - oops! – Nick Bolton Mar 01 '10 at 18:35
-
I had mysql 5.5 installed on my raspbian jessie. After an upgrade, I do not know why but it was left misconfigured, which prevented it from being uninstalled properly. Your answer did completely remove mysql 5.5 server and I was able to update. Beware you will lose config files (datyabases?) if you do not make backups. – joninx Feb 22 '17 at 16:02
-
`sudo apt purge 'mysql-*'` (without the dot) in Debian 11. – Rodrigo Feb 07 '23 at 01:19
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.

Nick Bolton
- 5,126
- 12
- 54
- 62
-
If you are using 5.0 and above then `apt-get purge ...` is the same as `apt-get --purge remove ...` – Zoredache Feb 10 '10 at 00:03
1
I had some problems with that. Even after removing all the server packages, there are some config files installed by mysql-common
, which is a dependency of libmysqlclient
.
Try using dpkg -S /etc/mysql
to see which packages are installing those files.

Jorge Bernal
- 454
- 1
- 3
- 9
0
You can also use dpkg -P to achieve this
From the dpkg man page
-P or --purge removes everything, including configuration files.

Dominik
- 2,218
- 14
- 9