MariaDB and Debian 7 logos on a pale yellow background

DevOps Deployment Automation with Terraform, AWS and Docker

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.


DevOps Deployment Automation with Terraform, AWS and Docker

7 replies
  1. Chad Taylor
    Chad Taylor says:

    I keep getting these errors… (I am very new to servers)

    The following packages have unmet dependencies:
    mariadb-common : Depends: mysql-common but it is not going to be installed
    phpmyadmin : Depends: php5-mysql but it is not going to be installed or
    php5-mysqli but it is not installable or
    php5-mysqlnd but it is not going to be installed
    Recommends: mysql-client or
    mariadb-client but it is not going to be installed or
    E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

  2. Ahmed Elkoussy
    Ahmed Elkoussy says:

    Thank you very much , I was stuck at removing mariadb , for some reason it kept there and prevented installing mysql-server on ubuntu

  3. GeraldBrown
    GeraldBrown says:

    This was a life saver for me.
    I had tried to set up a Galera cluster on a 2 node system. The first node was running OK but the server on node 2 would NOT boot up. I stopped node 1 and tried to start node. Now it was NO GO on either node. Have been trying all day to get them back online but was only able to do it after reading this.
    Thanks alot.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.