How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Remove MariaDB Completely from RHEL/CentOS
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Remove MariaDB Completely from RHEL/CentOS
Server Management

How to Remove MariaDB Completely from RHEL/CentOS

how7o
By how7o
Last updated: May 22, 2026
5 Min Read
Completely remove MariaDB from a RHEL-family server
SHARE

To completely remove MariaDB from RHEL, AlmaLinux, Rocky, or CentOS, stop the service, uninstall the packages, then delete the data directory and config file. After that you can either reinstall fresh or move on. Back up your databases first — the data-directory delete is destructive.

Contents
  • Back up first (do not skip)
  • Stop the service
  • Uninstall the packages
  • Delete the data directory
  • Delete config files
  • Reinstall (optional)
  • Restore data (if you backed up earlier)
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on AlmaLinux 9 and CentOS 7. Originally published 2022-12-06, rewritten and updated 2026-05-17.

Back up first (do not skip)

# If MariaDB still starts, take a logical dump
sudo mysqldump --all-databases --routines --events \
    | gzip > /root/mariadb-dump-$(date +%F).sql.gz

# Always take a raw snapshot of the data dir + config
sudo tar czf /root/mariadb-files-$(date +%F).tgz \
    /var/lib/mysql /etc/my.cnf /etc/my.cnf.d
Remove MariaDB on RHEL — stop service, dnf/yum remove, delete data dir, reinstall

Stop the service

sudo systemctl stop mariadb
sudo systemctl disable mariadb

Uninstall the packages

# AlmaLinux / Rocky / RHEL 8 and 9
sudo dnf remove mariadb mariadb-server -y

# CentOS 7 (legacy / EOL)
sudo yum remove mariadb mariadb-server -y

This removes binaries, scripts, and any package-managed config under /etc/my.cnf.d/. It does not remove your data directory or any /etc/my.cnf you wrote manually — those steps come next.

Delete the data directory

# Default location
sudo rm -rf /var/lib/mysql

# If you set datadir to a different path in my.cnf, use that path

Every database, every user, every grant lives here. Skipping this step is the right move if you want to keep the data and just reinstall the binaries — but for a true clean slate, this directory has to go.

Delete config files

sudo rm -f /etc/my.cnf
sudo rm -f ~/.my.cnf
sudo rm -rf /etc/my.cnf.d

/etc/my.cnf may already be gone after package removal; ~/.my.cnf (root’s client credentials) often survives and is worth cleaning up.

Reinstall (optional)

# RHEL-family 8/9
sudo dnf install mariadb mariadb-server -y
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

# CentOS 7
sudo yum install mariadb mariadb-server -y
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

mysql_secure_installation walks through setting the root password, removing the anonymous user, and disabling remote root login. Do this immediately after install.

Restore data (if you backed up earlier)

# From a logical dump
gunzip < /root/mariadb-dump-2026-05-17.sql.gz | sudo mysql

# Verify
sudo mysql -e 'SHOW DATABASES;'

Frequently asked questions

Is removing /var/lib/mysql destructive?

Yes — that directory contains every database, user, and grant on the server. Back it up first: sudo tar czf /root/mysql-backup-$(date +%F).tgz /var/lib/mysql /etc/my.cnf before deleting. If you only want to repair a corrupted install, try innodb_force_recovery mode first; full wipe is a last resort.

What’s the difference between yum remove and dnf remove?

yum is the legacy command on CentOS 7 (now EOL); dnf is the modern replacement used on AlmaLinux/Rocky/RHEL 8 and 9. They take the same arguments for basic install/remove operations. On RHEL 8+, yum is a symlink to dnf, so either works.

Does this remove every trace, including SELinux context?

Almost — the steps remove the binaries, data, and config files. SELinux file contexts attached to /var/lib/mysql go with the directory; if you reinstall, the package’s %post scriptlets restore them. If you ever see permission denied from MariaDB after a reinstall, run sudo restorecon -R /var/lib/mysql to reset SELinux contexts.

Should I disable the service before removing?

Yes — stop and disable first so any in-progress writes finish cleanly and nothing tries to restart the service during removal: sudo systemctl stop mariadb; sudo systemctl disable mariadb. Some package builds do this automatically during remove, but doing it explicitly is the safer order.

Related guides

  • How to Troubleshoot MariaDB Not Starting
  • How to Restart the MariaDB Server
  • How to Install MySQL on Ubuntu

References

MariaDB Knowledge Base: mariadb.com/kb/en. AlmaLinux project: almalinux.org. CentOS end-of-life notice: redhat.com/en/topics/linux/centos-linux-eol.

TAGGED:configurationLinuxmariadbmysql

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Remove all non-numeric characters from a PHP string How to Remove All Non-Numeric Characters from a String in PHP
Next Article Safely remove MySQL binary log files to free disk space How to Safely Clean Up MySQL Binary Log Files
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Check Ubuntu version — terminal and Settings
Server Management

How to Check Your Ubuntu Version

4 Min Read
Laravel updateOrCreate method shown in an Eloquent code snippet with insert and update branches
Web Development

Laravel updateOrCreate: Insert or Update Records in Eloquent

8 Min Read
Enable the PHP DOM extension on a Linux server
Server Management

How to Enable the PHP DOM Extension

5 Min Read
Replace strings in a MySQL database with UPDATE and REPLACE()
Web Development

How to Replace Strings in a MySQL Database

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?