06 July 2020
If you are thinking about completely uninstalling MySQL, it is not as straightforward as it sounds. This tutorial will provide you with step by step instructions on how to perform a clean uninstall of MySQL on your MacBook.
If you want to retain your databases when MySQL is deleted, make sure that you make a backup of them.
mysqldump command creates a text file dump of your databases. If you decide to recreate them at a later stage, it is easy to do so when you have a backup with the .sql extension.
To create a backup,
Hit command + space to bring up the Spotlight Search.
Search for Terminal and click on it.
Type the command below to navigate to the file containing the binaries of MySQL.
Type the command below, and it will create a file called all_databases.sql.
This file will contain queries that could be used to restore your databases, which will come useful should you require to build them back.
Now that you have made a backup let's go ahead and perform a clean uninstall of MySQL.
This step could be easily done from the System Preferences panel. However, you could perform the same step from the Terminal itself. Let's look at both ways in detail.
Navigate to System Preferences.
Towards the bottom of the panel, you will find the MySQL service. Click on it and navigate to the MySQL panel.
Click on Stop MySQL Server.
For those of you who used Homebrew to install MySQL, please enter the command below to stop the MySQL server.
To check if the command worked, you can list the services by running the following command.
Check if the status of MySQL has changed to 'stopped.'
If you installed MySQL by other means, please follow these steps.
Type the command below to navigate to the file containing the binaries of MySQL.
Then run the following command to stop the MySQL server.
If you have set up your root account without a password,
If you have set up your root account with a password,
(please replace password with your root password when entering the command)
To ensure the command has worked, you can navigate to the MySQL pane from the System preferences panel and see if the button has changed from Stop MySQL Server to Start MySQL Server.
These steps are essential when uninstalling MySQL as you will be unable to install an older version of MySQL if these elements remain in your macOS environment.
To remove the MySQL folder and all of its contents,
If prompted, please enter the password.
Executing both the commands will ensure that you will delete the MySQL folder and any symbolic link pointing to that folder.
To remove Startup Items and the Preferences panes,
The Receipts folder contains elements of MySQL that are created while the MySQL server is running. To delete this folder,
These commands will ensure that your MacOS environment is completely free from any elements created by MySQL while installing and running.
Please note that depending on how you have run MySQL, one or more files will not be available in your system. If any of the commands are giving you a, "no matches found" error, please ignore it.
By following the steps, you have successfully uninstalled MySQL. Now you can install a different version of MySQL and restore the databases using the backup you created.