14

Installed MySQL by issuing the following commands:

$ brew install mysql56
$ brew services start mysql@5.6

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 mysql@5.6

It shows:

Service `mysql@5.6` already started, use `brew services restart mysql@5.6` to restart.

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

zseikyocho
  • 621
  • 2
  • 9
  • 18

1 Answers1

37

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!

JayRizzo
  • 3,234
  • 3
  • 33
  • 49
  • Thank you for your answer. But it also don't work for `mysql56` - `mysql@5.6`. I can't find mysql using this command: `sudo launchctl list | grep -i mysql`. But still this message shown: `Service `mysql@5.6` already started, use `brew services restart mysql@5.6` to restart.`. – zseikyocho Sep 04 '18 at 06:49
  • No problem. did you install this another time using https://dev.mysql.com/downloads/mysql/ ? Reason I ask, is I ran into this too, but solved it by removing `brew`'s `mysql` and just set it up directly from the `.dmg` file. After you uninstalled it, did you restart your computer and check to see if it was still running? If so then you have an outlier. – JayRizzo Sep 04 '18 at 06:53
  • 2
    Thank you very much. I did `brew remove mysql56` and `brew install mysql56` again. It works! Make sure this path should been replaced: `/usr/local/opt/mysql@5.6`. – zseikyocho Sep 04 '18 at 07:01
  • What do you mean `Replaced` could you elaborate? – JayRizzo Sep 04 '18 at 07:03
  • 1
    After ran `brew remove mysql56` the path `/usr/local/opt/` shouldn't contain `mysql@5.6` folder. It will regenerate when ran `brew install mysql56` again. – zseikyocho Sep 04 '18 at 07:05
  • Thank you for your kindly help:) – zseikyocho Sep 04 '18 at 07:28
  • 1
    Thanks! The running instance was the culprit. Even if we already unistalled using brew command and the folder already deleted, somehow if we use docker and try to connect to the container, it will failed. – Erick Nyoto Aug 15 '21 at 14:23