Lab / Local Server / DevOPS

How to completely remove Mysql from Mac OSX

Today I found a rarely installed Mysql in my old MacBook, which I didn't used for years. So let's to fix it together.

If you are not afraid to execute a few lines of code in your Mac terminal, then everything is not so scary.

So, here are the lines you need to execute:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*

If you have a rather old version of OSX, you may need to delete the line MYSQLCOM = -YES- in the hostconfig file.

sudo vim /etc/hostconfig (remove line MYSQLCOM=-YES-)

I hope you can use Vim. And if such a line could not be found in this file, then it's okay, this config is simply not written in newer versions of OSX. We close the terminal, the deal is done. Can I install Mysql on a new one, or can it? and is it time to move on from what is more sane? =)

Uninstalling Mysql via Homebrew

If the installation was done through Homebrew, you will need the following sequence of commands.

First, stop all Mysql processes for example brew services stop mysql or restart the computer if Mysql is not in autorun.

Then run the following commands in sequence:

ps -ax | grep mysql
brew remove mysql
brew cleanup
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*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
edit /etc/hostconfig Remove line (if exist) MYSQLCOM=-YES-
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*

Restart the computer for reliability.