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

时间:2018-09-04 01:51:26

标签: mysql mysql-5.6 process homebrew

通过发出以下命令来安装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.

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

1 个答案:

答案 0 :(得分:2)

堆栈溢出。

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

尝试一下

brew uninstall --force mysql

或者来自Google,第一个结果来自CoderWall

查找任何正在运行的实例

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

如果运行终止进程

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失败了,只是不存在。

希望这对您有帮助并度过愉快的一天!