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
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026

You Might Also Like

Fix broken cPanel disk quotas with the fixquotas script
Server Management

How to Fix Quotas in cPanel

5 Min Read
Laravel get config variable — config() helper and Config facade resolving dotted keys
Web Development

How to Get Config Variables in Laravel

7 Min Read
Laravel Eloquent group by count — Book::groupBy('author') query with bar-chart aggregate icon
Web Development

How to Count Records Grouped By a Column in Laravel Eloquent

7 Min Read
How to temporarily disable Imunify360 service for testing (cPanel/WHM)
Server Management

How to Temporarily Disable Imunify360 Service (Safe Testing + Fix 503)

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?