1. 卸载并完全删除
brew services stop mysql
ps -ax | grep mysql

kill mysql

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


下面的在我的文件夹中完全没有

subl /etc/hostconfig` 
# Remove the line MYSQLCOM=-YES-

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*

重启
  1. 安装
brew install mysql
mysql.server start #停止服务mysql.server stop 或 brew services stop mysql
  • 提示
Starting MySQL
. SUCCESS! 
  • 启动成功
  1. 登录并改密
mysql -u root #安装完成默认免密登录
alter user 'root'@'localhost' identified with mysql_native_password by 'root'; #8.0版本改密
  • 输出:
Query OK, 0 rows affected (0.00 sec)
  • 改密成功
  • exit; 退出MySQL
  • 重新连接MySQL: mysql -u root -p
  1. 创建用户并指定对某一数据库有权限(在root用户下进行)
CREATE USER 'passwd' IDENTIFIED BY '123456'; #用户名passwd,密码123456
select user(); #查看当前用户
select user,host from mysql.user; #查看MySQL中所有用户
show grants for 'passwd'@'%'; #查看用户passwd的权限信息
grant select,insert,update,delete,create,alter on test.* to 'passwd'; #授予passwd查询和添加test库的权限
grant all privileges on test.* to 'passwd'@'%' identified by "123456" with grant option; #授予passwd对test库所有操作
  1. 导入数据库
  • mysql -uroot -p123456 test < mydb.sql