How to completely uninstall MySQL from your system

Updated: January 25, 2024 By: Guest Contributor Post a comment

Introduction

MySQL, owned by Oracle, is one of the most widely used open-source relational database management systems (RDBMS). While it’s beneficial to have MySQL installed to manage databases for various applications, there may come a time when you need to uninstall MySQL from your system. This process may involve a bit more than simply dragging a folder to the trash or using a basic uninstall command. In this guide, we will take a step-by-step approach to completely remove MySQL and all its associated files from your system.

This tutorial will focus on uninstalling MySQL from different operating systems such as Windows, macOS, and Linux. We will provide detailed instructions as well as code examples and expected outputs to ensure a smooth uninstallation process.

Uninstalling MySQL on Windows

To uninstall MySQL from a Windows OS, you need to follow these steps:

  1. Open the Control Panel.
  2. Navigate to ‘Programs’ -> ‘Programs and Features’.
  3. Select MySQL Server from the list and click the ‘Uninstall’ button.

After the uninstallation process is complete, you should remove any remaining service instances. Open up the Command Prompt as an administrator and type the following:

sc delete mysql

If the service is not named ‘mysql’ on your system, replace ‘mysql’ with the correct service name in the above command.

Delete the remaining files and folders manually. You might find MySQL installed in the ‘Program Files’ or ‘ProgramData’ folder. Ensure that you have shown hidden files and folders, and then delete the MySQL folders:

rmdir /S "C:\Program Files\MySQL"
rmdir /S "C:\ProgramData\MySQL"
rmdir /S "C:\Users\[YourUsername]\AppData\Roaming\MySQL"

Replace ‘[YourUsername]’ with your actual username on your Windows system.

Next, you’ll have to clean any MySQL entries from the Windows Registry. Be cautious when editing the registry and ensure to backup before making any changes. Run the Registry Editor (regedit) and delete the following keys:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MySQL
HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB

Uninstalling MySQL on macOS

Uninstalling MySQL on a Mac system is not much different from the process on Windows, but it requires some terminal commands. Here are the steps:

  1. Open Terminal.
  2. Stop the MySQL service using the following command:
sudo /usr/local/mysql/support-files/mysql.server stop

Remove the MySQL folder:

sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM

You should also unload the launch agents that automatic start MySQL:

launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysql.plist
rm ~/Library/LaunchAgents/com.mysql.mysql.plist

Finally, you need to remove the MySQL preferences and cached files:

rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*

Uninstalling MySQL on Linux

The process to remove MySQL on Linux systems varies between distributions. Here’s a general guide that applies to systems using the `apt-get` package manager (like Ubuntu).

Stop the MySQL service:

sudo service mysql stop

Remove the MySQL packages:

sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean

Delete the MySQL configuration and data files:

sudo rm -rf /etc/mysql /var/lib/mysql
sudo rm -rf /var/log/mysql*

And again, you can also remove the MySQL users:

sudo deluser mysql
sudo delgroup mysql

Note that these commands may need to be adapted if you’re using a different package manager like `yum` or `dnf` for Red Hat-based systems or `zypper` for openSUSE systems.

Advanced Uninstallation Tips

If you have custom configurations, you may need to manually search and remove those configurations from your system. Use the following command to search for any remaining MySQL related files:

sudo find / -iname '*mysql*'

Carefully check the resulting list and delete the files that are meant to be removed. Make sure not to remove system files essential for other applications.

Conclusion

After following the steps in this tutorial, MySQL should be completely removed from your system. While most uninstalled data and service instances will be cleansed through established processes, checking for residual configuration files is good practice. As always, when dealing with system configurations and uninstalling core software components meticulously, ensure every step is understood and properly executed to avoid unintended consequences.