Search code examples
mysqlmysql-5.6processhomebrew

How to uninstall MySQL 5.6 when installed by brew on macOS?


Installed MySQL by issuing the following commands:

$ brew install mysql56
$ brew services start [email protected]

Now I can't access it:

$ mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Want to uninstall it and tried the following:

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/MySql*

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

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 computer)

Now work.

When I install it again and run:

brew intall mysql56
brew services start [email protected]

It shows:

Service `[email protected]` already started, use `brew services restart [email protected]` to restart.

But I can't find it in the process list.


Solution

  • to Stack Overflow.

    I will answer this but, please be sure to check for existing questions as this has already been asked.

    Try this

    brew uninstall --force mysql
    

    Or From Google First result being from CoderWall

    Find Any Running Instances

    ps -ax | grep mysql | grep -v grep
    
    # OR for only the running `PID`
    
    ps -ef | grep mysql | grep -v grep | awk '{print $2}'
    
    # OR this If you have this on your machine, I recommend using 
    
    pgrep -f mysql
    

    If running the kill process

    kill 24024824082408   # change this number to what was returned in the grep 
    

    Save your database data

    This will save your MySQL Data Folder to your desktop in a folder mysqldata.

    # I backup my data from mysql to my desktop
    mkdir ~/Desktop/mysqldata/
    
    # data
    cp -r /usr/local/mysql/data ~/Desktop/mysqldata
    

    Save your MySQL Workbench Data for migration.

    # MySQL workbench active sessions including the unsaved query windows
    cp -r ~/Library/Application\ Support/MySQL/Workbench/sql_* ~/Desktop/mysqldata
    
    # data this is a log containing queries that were logged at some point, more of a `just in case`
    cp ~/Library/Application\ Support/MySQL/Workbench/log/sql_actions_unconnected.log ~/Desktop/mysqldata/sql_actions_unconnected.sql
    
    # data of user snippets as people forget about this.
    cp /Users/`id -un`/Library/Application\ Support/MySQL/Workbench/snippets/User\ Snippets.txt ~/Desktop/mysqldata/UserSnippets.txt
    

    Removal and Cleanup

    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
    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*
    

    Edit (if applicable) vi /etc/hostconfig and remove the line MYSQLCOM=-YES-

    Restart your computer if you want to ensure any MySQL processes are killed Try to run mysql, it shouldn't work.

    Don't worry about some of the rm's failing they are just nonexistent.

    Hope this helps & have a great day!