In this article, you will find how to uninstall MySQL in Linux and Windows. It can be tricky, but these simple steps will guide you through the process for Linux and Windows.
Follow the steps:
Uninstalling MySQL on Linux
- Remove MySQL Using the Package Manager commands:
Run the appropriate command based on your Linux distribution:- CentOS/RedHat:
sudo yum remove mysql mysql-server
- Ubuntu/Debian:
sudo apt remove mysql mysql-server
- Fedora:
sudo dnf remove mysql mysql-server
- CentOS/RedHat:
- Handle the Data Directory
The default data directory is “/var/lib/mysql.”:- Rename it for backup:
sudo mv /var/lib/mysql /var/lib/mysql_backup
- Or delete it entirely if not needed.
Note: Renaming is safer if you want to keep a backup of your data.
- Rename it for backup:
- Reinstalling MySQL (Optional)
You have now successfully uninstalled MySQL from your Linux server. To reinstall it, use your distribution’s package manager and replace the “remove” commands above with the “install” command.- For CentOS and RedHat users:
sudo yum install mysql mysql-server
- For Ubuntu and Debian users:
sudo apt install mysql mysql-server
- For Fedora users (as well as for many secondary distributions):
sudo dnf install mysql mysql-server
- For CentOS and RedHat users:
Uninstalling MySQL on Windows
- First, you will have to uninstall MySQL from your Windows Control Panel:
Go to Control Panel > Programs and Features, find MySQL, and click “Uninstall.” - Open a terminal window as Administrator, then stop and delete the MySQL service by running these commands:
net stop MySQL sc delete MySQL
- Go to the Start menu, type “Show hidden files and folders”, select the “View” tab, and delete the following folders from your system:
C:\Program Files\MySQL C:\Program Files (x86)\MySQL C:\ProgramData\MySQL
If present, also delete:
C:\Users\[YourUsername]\AppData\Roaming\MySQL
- After uninstalling everything and deleting your MySQL data directories, restart your computer to confirm the changes.
Now MySQL is completely uninstalled, along with its data directories. If you find any difficulty in this process, feel free to contact our support staff.
Check out our guide: How to Add a User to a MySQL Database for step-by-step instructions.