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

  • 2026-02-01
  • OS
OS

1. Introduction

MySQL is a widely used database system, but there are cases where you may need to uninstall it, such as when reinstalling or changing versions. This guide explains in detail how to completely uninstall MySQL in both Windows and Linux environments. By properly removing residual files and service configurations, you can avoid potential issues during reinstallation.

2. Steps to Uninstall MySQL on Windows

2.1 Uninstalling from the Control Panel

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

2.2 Deleting Residual Files

Even after uninstalling the MySQL program itself, some residual files may remain on your system. Be sure to delete these files manually.

  1. Delete the MySQL folder in Program Files
    Locate and delete the C:\Program Files\MySQL folder.
  2. Delete MySQL-related files in the ProgramData folder
    Also delete the hidden folder C:\ProgramData\MySQL. If it is not visible, enable the “Show hidden files” option in File Explorer.

2.3 Removing the MySQL Path from Environment Variables

  1. Check Environment Variables
    Open “Environment Variables” from “Advanced system settings.”
  2. Remove the MySQL path from Path
    Edit the “Path” under “System variables” and remove MySQL-related paths (e.g., C:\Program Files\MySQL\MySQL Server).

3. Steps to Uninstall MySQL on Linux

3.1 Uninstalling Using a Package Manager

The package manager used depends 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 excels at resolving dependencies and efficiently managing complex packages. YUM also supports dependency resolution and allows installations from multiple repositories.

3.2 Deleting Data Folders and Configuration Files

  1. Delete the data folder
    Since MySQL data is stored in /var/lib/mysql, delete this folder.
   sudo rm -rf /var/lib/mysql
  1. Delete configuration files
    Also remove MySQL configuration files.
   sudo rm -rf /etc/mysql /etc/my.cnf

4. Removing the MySQL Service

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

4.1 Removing the Service on Windows

  1. Display the list of services
    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 Removing the Service 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, it is extremely important to back up your data. Since uninstallation may result in data loss, creating a backup is essential. Use the following command to back up all databases.

mysqldump -u root -p --all-databases > alldatabases.sql

5.2 Points to Consider When Reinstalling

When reinstalling MySQL, problems may occur if previous configuration files or databases remain. Therefore, it is important to verify that all related files have been completely removed after uninstallation.

6. Conclusion

In this article, we explained in detail the steps to uninstall MySQL in both Windows and Linux environments. In particular, removing residual files and services is essential for a complete uninstallation. By following the correct procedures, you can prevent issues during reinstallation.