macOS Mojave10.14.2 卸载/安装MySQL

 

卸载MySQL(dmg安装)

命令:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo vim /etc/hostconfig (Vim指令,复制上述命令,保存,退出即可)

继续完成下列指令:


rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
 

关闭终端

打开系统偏好设置,最下方MySQL图标消失

安装MySQL(用brew,MySQL版本8.0.13)

假设当前用户名为mayun,确保mysql.sock和mysql.sock.lock的owner为mayun:wheel;

具体见报错日志(设置在/etc/my.cnf的log-error);

以下命令首先清理brew安装的无法启动的MySQL,然后重新安装--初始化--启动;

注意一下,初始化步骤输出了初始化的root密码;

brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql

brew install mysql
mysqld --initialize --explicit_defaults_for_timestamp
mysql.server start # no sudo!

进入MySQL执行:mysql -uroot -p;

输入密码;

执行show databases;

报错:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

执行:ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

再次执行show databases;

 

 

你可能感兴趣的:(mac,MySQL)