Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7
Asked Answered
O

3

62

I installed MariaDB on CentOS 7 but I had some problems with some configuration, now it is completely misconfigured.

Thus, I wanted to remove the MariaDB with “yum remove mariadb mariadb-server”, after that I reinstalled it with “yum install mariadb mariadb-server”.

Unfortunately, the configuration remains. It seems as if yum remove don’t delete all MariaDB Config-Files.

How can I remove MariaDB completely from CentOS 7?

Occasionally answered 27/10, 2015 at 8:22 Comment(0)
H
104

These steps are working on CentOS 6.5 so they should work on CentOS 7 too:

(EDIT - exactly the same steps work for MariaDB 10.3 on CentOS 8)

  1. yum remove mariadb mariadb-server
  2. rm -rf /var/lib/mysql If your datadir in /etc/my.cnf points to a different directory, remove that directory instead of /var/lib/mysql
  3. rm /etc/my.cnf the file might have already been deleted at step 1
  4. Optional step: rm ~/.my.cnf
  5. yum install mariadb mariadb-server

[EDIT] - Update for MariaDB 10.1 on CentOS 7

The steps above worked for CentOS 6.5 and MariaDB 10.

I've just installed MariaDB 10.1 on CentOS 7 and some of the steps are slightly different.

Step 1 would become:

yum remove MariaDB-server MariaDB-client

Step 5 would become:

yum install MariaDB-server MariaDB-client

The other steps remain the same.

Hysteroid answered 28/10, 2015 at 14:38 Comment(4)
handy one liner to purge: sudo yum remove -y mariadb mariadb-server && sudo rm -rf /var/lib/mysql /etc/my.cnfStringfellow
// , Tested this on the CEntOS 7.5 Bento Vagrant Box, and it worked. Thanks, Ciprian.Ghats
Done this on Centos 7.6, everything ok. Thanks!Mareah
On centos-release-7-7.1908.0.el7.centos.x86_64 yum remove mariadb mariadb-server actually takes care for both client and server packages (version 10.4.11-1.el7.centos)Logistician
M
12

To update and answer the question without breaking mail servers. Later versions of CentOS 7 have MariaDB included as the base along with PostFix which relies on MariaDB. Removing using yum will also remove postfix and perl-DBD-MySQL. To get around this and keep postfix in place, first make a copy of /usr/lib64/libmysqlclient.so.18 (which is what postfix depends on) and then use:

rpm -qa | grep mariadb

then remove the mariadb packages using (changing to your versions):

rpm -e --nodeps "mariadb-libs-5.5.56-2.el7.x86_64"
rpm -e --nodeps "mariadb-server-5.5.56-2.el7.x86_64"
rpm -e --nodeps "mariadb-5.5.56-2.el7.x86_64"

Delete left over files and folders (which also removes any databases):

rm -f /var/log/mariadb
rm -f /var/log/mariadb/mariadb.log.rpmsave
rm -rf /var/lib/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql

Put back the copy of /usr/lib64/libmysqlclient.so.18 you made at the start and you can restart postfix.

There is more detail at https://code.trev.id.au/centos-7-remove-mariadb-replace-mysql/ which describes how to replace mariaDB with MySQL

Multinuclear answered 21/8, 2018 at 1:43 Comment(0)
G
8

systemd

sudo systemctl stop mysqld.service && sudo yum remove -y mariadb mariadb-server && sudo rm -rf /var/lib/mysql /etc/my.cnf

sysvinit

sudo service mysql stop && sudo apt-get remove mariadb mariadb-server && sudo rm -rf /var/lib/mysql /etc/my.cnf
Greenwald answered 30/3, 2018 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.