There are many guides about how to install and configure popular applications on Linux servers, but not much on how to remove them.

I found this out when I needed to install a MariaDB Galera cluster on a server which already had a stand-alone MariaDB server installed. Having the older version of MariaDB installed (and the older repository in the source list) meant all of the guides I was following didn’t work due to conflicting packages.

This guide will explain how to completely remove MariaDB from your system (including any databases).

Click here to download an easy-to-follow PDF version of this post

Here is how you remove MariaDB from a Debian 7 Linux server.

Stop any running instanced of MariaDB

First, you need to stop any running instances of MariaDB. To do this, type the following in the console:

sudo service mysql stop

Remove all MySQL packages from the system

Warning: this will delete all databases from your server. Make sure you have backed everything up before doing this.

Run the following command. This will use apt-get to remove all packages with the name beginning with “mysql”. The –purge switch tells it to purge all configs and related files from the system.

sudo apt-get --purge remove "mysql*"

After you run this, you will see something similar to this:

Apt-get message asking user to confirm the remove of packages

This is telling you what packages will be removed. If you wish to continue uninstalling MariaDB then press Y and hit enter.

If everything has worked as expected you will see this message:

MariaDB asking user to confirm removal of all databases on uninstall

If you are happy to lose all of your databases, select yes and press enter.

MariaDB is now removed.

Remove the configs file

Now MariaDB has been completely uninstalled, the next step is to ensure all configs are gone. the –purge switch we used earlier tells apt-get to remove all configs, however it will only remove the default configs that came with the install. Any custom configs that were added after the install will still be there.

The configs are usually located at /etc/mysql/. I would not suggest just deleting them (in-case you need them later). However I would suggest moving them to a different directory. This is how you would move them to the /tmp/ directory:

sudo mv /etc/mysql/ /tmp/mysql_configs/

Warning: Some servers are configured to delete the contents of the /tmp/ directory on reboot. If you want to keep the configs safe it’s best to move them to your home directory.

Remove from the source list

The final step is to remove the old package repositories from the sources file. This is what got me stuck when trying to install MariaDB Galera before, because I had the old repositories in the source list it would cause conflicts. Here is how you remove them:

First open the sources.list file in your editor of course (I use vi in this example):

vi /etc/apt/sources.list

In this file (usually near the bottom), locate the lines which contain “MariaDB”. Comment out these lines by appending a # to the beginning of them. This is how mine looks (although yours may vary depending on the version of MariaDB you previously had installed):

# wheezy-updates, previously known as 'volatile'
deb wheezy-updates main
# deb wheezy main
# deb-src wheezy main
deb-src wheezy-updates main

Now save the file.

The final step, is to update apt-get by running the below line:

sudo apt-get update

That’s it. MariaDB is now completely removed from your system. In order to re-install it, (or install Galera) you must follow the instructions on

Thank you for reading. I hope that you found this helpful. If you have any questions please write them in the comments below.

If you want to download a PDF version of this guide for your records (which I always suggest as best practice), click on the link below and we’ll send a copy right to your inbox.


Click here to download an easy-to-follow PDF version of this post