How to completely remove MYSQL on your localhost?
Sometimes, we thought a simple
brew remove mysql will remove the entire MySQL but in some cases, it does not. Here is how you can completely remove MySQL on your mac locally.
- Open your terminal.
Shortcut tip: CMD + Space >> type “ter” >> press enter, terminal will popup.
mysqldump to backup your databases.
mysqldump -h localhost -u userName -p databaseName > sqldump.sql
3. Stop MYSQL from running.
brew services stop mysql
If you have a specific version for MYSQL you can run this.
brew services stop firstname.lastname@example.org
4. Remove MYSQL.
brew remove mysql
5. Remove the remaining MYSQL files.
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
6. Unload MySQL login:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
7. Remove MYSQL configuration. You can use nano or vim.
and remove this line below
8. Remove the MYSQL preferences.
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*
You should have removed all the necessary files by now.
If you still face version or installation errors. You might want to kill the previous MySQL processes using the command below or restart your mac.
Kill the remaining MySQL process.
Check if all MYSQL processes are killed.
ps -ax | grep mysql
or check if the port 3306 is being used by any MYSQL process.
lsof -i :3306