How to Completely Uninstall MySQL on Windows and Linux (Step-by-Step Guide)

  • 2025-09-07
  • OS
OS

1. Introduction

MySQL is a widely used database system, but sometimes it needs to be uninstalled due to reinstallation, version changes, or troubleshooting. This guide provides detailed instructions on how to completely uninstall MySQL on both Windows and Linux environments. By carefully removing residual files and service configurations, you can avoid potential issues.

2. Uninstalling MySQL on Windows

2.1 Uninstall from Control Panel

  1. Open Control Panel From Windows “Control Panel,” select “Uninstall a program.”
  2. Uninstall MySQL-related programs Select and uninstall all MySQL-related programs such as “MySQL Server,” “MySQL Workbench,” and “MySQL Connector.”

2.2 Delete Residual Files

Even after uninstalling MySQL, some residual files may remain on your system. These files should be deleted manually.
  1. Delete the MySQL folder in Program Files Locate and delete the C:Program FilesMySQL folder.
  2. Delete MySQL files in ProgramData Also delete the hidden folder C:ProgramDataMySQL. If it is not visible, enable the “Show hidden files” option in File Explorer.

2.3 Remove MySQL Path from Environment Variables

  1. Check environment variables Go to “Advanced system settings” and open “Environment Variables.”
  2. Remove MySQL path from Path Edit the “Path” under “System variables” and delete any MySQL-related paths (e.g., C:Program FilesMySQLMySQL Server).

3. Uninstalling MySQL on Linux

3.1 Using Package Manager

The package manager varies depending on your Linux distribution. Use the following commands to uninstall MySQL.
  • Debian-based (Ubuntu, etc.)
   sudo apt-get remove --purge mysql-server mysql-client mysql-common
   sudo apt-get autoremove
   sudo apt-get autoclean
  • RedHat-based (CentOS, etc.)
   sudo yum remove mysql-server
APT is efficient at resolving dependencies and managing complex packages. On the other hand, YUM also supports dependency resolution and allows installations from multiple repositories.

3.2 Delete Data Folder and Configuration Files

  1. Delete the data folder MySQL data is stored in /var/lib/mysql, so delete this folder.
   sudo rm -rf /var/lib/mysql
  1. Delete configuration files Remove MySQL configuration files as well.
   sudo rm -rf /etc/mysql /etc/my.cnf

4. Remove MySQL Services

If MySQL services remain on the system, errors may occur during reinstallation. Remove the services to return the system to a clean state.

4.1 Remove Services on Windows

  1. Open service list Open services.msc and locate the MySQL service.
  2. Stop and delete the service After stopping the MySQL service, delete it using the following command:
   sc delete MySQL

4.2 Remove Services on Linux

  1. Stop the service
   sudo systemctl stop mysql
  1. Disable the service
   sudo systemctl disable mysql

5. Important Notes After Uninstallation

5.1 Importance of Data Backup

Before uninstalling MySQL, backing up your data is crucial. Since data may be lost during uninstallation, backups are essential. Use the following command to back up all databases:
mysqldump -u root -p --all-databases > alldatabases.sql

5.2 Precautions for Reinstallation

When reinstalling MySQL, leftover configuration files or databases may cause issues. Therefore, it is important to ensure all related files are deleted after uninstallation.

6. Conclusion

This article explained the steps to uninstall MySQL on both Windows and Linux in detail. In particular, it is crucial to delete residual files and services for a complete uninstallation. Following the correct procedure helps prevent problems during reinstallation.