如何在 macOS 上通过 brew 安装时卸载 MySQL 5.6?

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

已通过发出以下命令安装 MySQL:

$ brew install mysql56
$ brew services start mysql@5.6

现在我无法访问它:

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

想卸载它并尝试了以下方法:

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)

现在工作。

当我再次安装它并且运行:

brew intall mysql56
brew services start mysql@5.6

显示:

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

但是我在进程列表中找不到。

到 Stack Overflow。

我会回答这个问题,但是请务必check for existing questions,因为已经有人问过了。

试试这个

brew uninstall --force mysql

或来自Google First result being from CoderWall

找到任何 运行 个实例

ps -ax | grep mysql | grep -v grep

# OR for only the running `PID`

ps -ef | grep mysql | grep -v grep | awk '{print }'

# OR this If you have this on your machine, I recommend using 

pgrep -f mysql

如果运行终止进程

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

保存您的数据库数据

这会将您的 MySQL 数据文件夹保存到桌面的文件夹 mysqldata 中。

# I backup my data from mysql to my desktop
mkdir ~/Desktop/mysqldata/

# data
cp -r /usr/local/mysql/data ~/Desktop/mysqldata

保存您的 MySQL Workbench 迁移数据。

# 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

删除和清理

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*

编辑(如果适用)vi /etc/hostconfig 并删除行 MYSQLCOM=-YES-

如果要确保任何 MySQL 个进程被终止,请重新启动计算机 尝试 运行 mysql,应该不行。

不要担心某些 rm 的失败,它们根本不存在。

希望这对您有所帮助,祝您有愉快的一天!