How to completely uninstall MariaDB from a Debian 7 server
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).
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:
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:
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 http://ftp.uk.debian.org/debian/ wheezy-updates main
# deb http://lon1.mirrors.digitalocean.com/mariadb/repo/5.5/debian wheezy main
# deb-src http://lon1.mirrors.digitalocean.com/mariadb/repo/5.5/debian wheezy main
deb-src http://ftp.uk.debian.org/debian/ 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 https://mariadb.org/
Thank you for reading. I hope that you found this helpful. If you have any questions please write them in the comments below.
Cheers,
Mark
Your code boxes are editable.
Oh strange lol. I’ll look into fixing it. Thanks for pointing it out.
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
virtual-mysql-client
E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).
Did you follow the step?
Try ‘apt-get -f install’ with no packages
Put on terminal: “apt-get -f install” and install those dependencies… Cheers!
Life saver!!!
Thank you for this. 🙂
Thank you very much , I was stuck at removing mariadb , for some reason it kept there and prevented installing mysql-server on ubuntu
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.