How to Perform a Complete MySQL Uninstall on Windows: Removing All Traces and Configuration Files


3 views

Many developers face this frustrating scenario: You uninstall MySQL through Windows Control Panel, delete the installation directory, yet when you reinstall, your old databases magically reappear. This happens because MySQL stores data and configuration files in locations separate from the main installation directory.

To ensure a clean slate, follow these steps in order:

1. Stop MySQL service:
   net stop MySQL
   (or whatever your MySQL service name is)

2. Uninstall via Control Panel:
   - Navigate to Programs and Features
   - Select MySQL and click Uninstall

After standard uninstallation, manually remove these directories:

- Program Files\MySQL
- Program Files (x86)\MySQL
- ProgramData\MySQL (hidden folder)
- Users\[YourUserName]\AppData\Roaming\MySQL

To delete ProgramData (which contains your databases), you'll need to show hidden folders in Windows Explorer.

For a thorough cleaning, remove MySQL registry entries. Backup your registry first:

1. Open regedit
2. Navigate to:
   HKEY_LOCAL_MACHINE\SOFTWARE\MySQL
   HKEY_CURRENT_USER\SOFTWARE\MySQL
3. Delete all MySQL-related keys

Before reinstalling, check these locations:

where mysql
sc query | find "MySQL"

These commands should return no results if MySQL is truly gone.

When reinstalling:

1. Use a different installation path
2. Specify a new data directory
3. Choose different port if previous install had conflicts
4. Create new root password

For power users, here's a batch script to automate parts of the process:

@echo off
net stop MySQL
timeout /t 3 /nobreak

rd /s /q "C:\Program Files\MySQL"
rd /s /q "C:\Program Files (x86)\MySQL"
rd /s /q "%ProgramData%\MySQL"

echo MySQL files removed. Manual registry cleanup required.
pause

When I first tried uninstalling MySQL from my Windows machine, I followed what seemed like standard procedure: ran the uninstaller, deleted the program files, and rebooted. To my surprise, after reinstalling, all my old databases magically reappeared. This led me down a rabbit hole of MySQL's Windows persistence mechanisms.

MySQL maintains several locations beyond its installation directory:

  • Data Directory: Typically in C:\ProgramData\MySQL\MySQL Server X.Y\data (hidden folder)
  • Registry Entries: Under HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB
  • Service Configuration: Windows service entries remain after uninstall

Here's the nuclear option to wipe MySQL completely:

1. Proper Uninstallation

First, use the official uninstaller through either:

Control Panel → Programs → Uninstall MySQL Server
or
"C:\Program Files\MySQL\MySQL Installer\MySQLInstallerConsole.exe" remove mysql-server

2. Manual File Cleanup

Delete these directories (adjust paths for your version):

rmdir /s /q "C:\Program Files\MySQL"
rmdir /s /q "C:\ProgramData\MySQL"
rmdir /s /q "C:\Users\[YourUser]\AppData\Roaming\MySQL"

3. Registry Cleanup

Warning: Back up registry first (reg export):

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL" /f

4. Service Removal

Even if uninstalled, sometimes services linger:

sc delete MySQL

Create this PowerShell script to check for remnants:

# Check for MySQL processes
Get-Process | Where-Object {$_.ProcessName -like "*mysql*"}

# Check for remaining services
Get-Service | Where-Object {$_.DisplayName -like "*MySQL*"}

# Check registry
Test-Path "HKLM:\SOFTWARE\MySQL AB"

For frequent MySQL reinstalls, save this as purge_mysql.bat:

@echo off
:: Stop and delete service
net stop MySQL 2>nul
sc delete MySQL 2>nul

:: Remove directories
rd /s /q "C:\Program Files\MySQL" 2>nul
rd /s /q "C:\ProgramData\MySQL" 2>nul

:: Clean registry
reg delete "HKLM\SOFTWARE\MySQL AB" /f 2>nul
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\MySQL" /f 2>nul

echo MySQL completely removed from system
pause

When reinstalling:

  • Use a different service name if testing multiple instances
  • Specify a custom data directory during installation
  • For development, consider using Docker containers instead

The official installer includes a cleanup utility:

"C:\Program Files\MySQL\MySQL Installer for Windows\MySQLInstaller.exe" cleanup