MariaDB
MySQL
CentOS 7
RHEL 7
Uninstall Guide

Completely remove MariaDB or MySQL from CentOS 7 or RHEL 7

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Removing MariaDB or MySQL completely on CentOS 7 or RHEL 7 means more than uninstalling one package. You usually need to stop the service, remove installed RPM packages, delete configuration and data directories if you truly want a clean slate, and verify that no custom repository packages remain behind. The dangerous part is the data directory, so back up anything you care about before you start.

Stop the Service and Inspect What Is Installed

Begin by stopping the database and checking which related packages are present.

bash
1sudo systemctl stop mariadb
2sudo systemctl disable mariadb
3
4rpm -qa | grep -Ei 'mariadb|mysql'

If the host is running MySQL instead of MariaDB, the service name may be mysqld.

bash
sudo systemctl stop mysqld
sudo systemctl disable mysqld

The package listing matters because systems often contain a mix of server, client, development, and shared-library packages. Removing only the server package leaves a half-installed environment behind.

Remove the Installed Packages

Once you know what is installed, remove the matching packages with yum.

bash
sudo yum remove mariadb mariadb-server mariadb-libs mariadb-devel

For Oracle MySQL packages, the names are often different.

bash
sudo yum remove mysql mysql-server mysql-community-server mysql-community-client mysql-community-common

If you are unsure of the exact package names, use the rpm -qa output and remove what is actually present. On older systems, it is normal to run the remove command more than once while you clean up dependencies.

Delete Configuration and Data for a True Reset

Uninstalling packages does not necessarily remove the database files. If the goal is a full reset before reinstalling, remove the configuration and data directories manually.

bash
1sudo rm -rf /etc/my.cnf
2sudo rm -rf /etc/my.cnf.d
3sudo rm -rf /var/lib/mysql
4sudo rm -rf /var/log/mariadb
5sudo rm -rf /var/log/mysql

This is the irreversible step. Do it only after backups are complete.

If your installation used custom paths, inspect the old configuration first. Many production systems store the datadir, socket, or log files somewhere other than the defaults.

bash
sudo grep -R "datadir\|socket\|log-error" /etc/my.cnf /etc/my.cnf.d 2>/dev/null

If custom paths were configured, remove those directories too, but only after confirming they belong to the old database installation.

Clean Up Repositories and Residual State

Some systems have third-party repositories that will reinstall MySQL or MariaDB packages during the next update. Check your repository definitions if you plan to switch vendors.

bash
ls /etc/yum.repos.d
sudo grep -R "mysql\|mariadb" /etc/yum.repos.d

If you installed Oracle's MySQL community repo, remove or disable that repository before installing MariaDB, and do the reverse if you are moving from MariaDB to MySQL. Otherwise, package conflicts are common.

After cleanup, verify that no packages remain.

bash
rpm -qa | grep -Ei 'mariadb|mysql'

An empty result is what you want for a truly clean uninstall.

Verify the System Is Clean

A final pass helps avoid confusing reinstall problems later.

bash
which mysql || true
which mariadb || true
sudo systemctl list-unit-files | grep -Ei 'mariadb|mysql'

If binaries still exist under custom paths such as /usr/local/mysql, that usually means the software was installed manually rather than through RPM. In that case, remove the manual installation directory separately.

Common Pitfalls

The biggest mistake is deleting /var/lib/mysql before taking a backup. Package removal can be undone with a reinstall, but data deletion cannot.

Another common mistake is removing the server package and assuming the job is done. Leftover shared libraries, client tools, repo definitions, or config files can interfere with the next installation.

Developers also sometimes forget that the active service name may differ. MariaDB commonly uses mariadb, while Oracle MySQL often uses mysqld. Stopping the wrong unit leaves the real process running.

Finally, be careful with automation or copy-pasted rm -rf commands. Confirm the path before you run destructive commands as root, especially on older production systems where configuration may be nonstandard.

Summary

  • A full MariaDB or MySQL removal on CentOS 7 or RHEL 7 requires more than a package uninstall.
  • Stop and disable the active service first, then inspect installed RPM packages.
  • Remove all related packages with yum based on what is actually installed.
  • Delete config and data directories only if you truly want a clean reset and already have backups.
  • Check repository files and residual binaries so the next install does not inherit old state.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design