How7oHow7o
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Remove MariaDB Completely from RHEL/CentOS
Share
Notification Show More
Font ResizerAa
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
    • All Tools
    • Image Tools
    • Text & String Tools
    • Video Tools
    • Developer Tools
    • PDF Tools
    • Calculators & More
  • 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.

You Might Also Like

Comment in a .gitignore file with the # character
Web Development

How to Comment in a .gitignore File

4 Min Read
Nginx redirect www to non-www or vice versa
Server Management

How to Redirect www to non-www (or vice versa) in Nginx

5 Min Read
MariaDB restart on Linux — systemctl restart mariadb
Server Management

How to Restart the MariaDB Server on Linux

6 Min Read
Install and configure Redis on Ubuntu for Laravel and WordPress
Server Management

How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)

10 Min Read
How7oHow7o

Free browser-based tools, prank screens, and step-by-step tech tutorials. No signup, nothing uploaded.

  • Private by design — your files never leave your device
  • Instant — no signup, no install, no waiting
  • Always free — no trials, no watermarks, no paywalls

Tools

  • PDF Editor
  • Image Upscaler
  • JPEG Compressor
  • Password Generator
  • QR Code Generator
  • Video Trimmer
  • See all tools →

Pranks

  • Cracked Screen Prank
  • Fake Blue Screen (BSOD)
  • Fake Disk Format
  • Fake Low Battery
  • Fake Virus Scan
  • Fake Windows 10 Update
  • 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?