MacOS上安装 MySQL5.7

如何在 Mac 上安装 Mysql5.7版
更新于: 2022-02-22 14:57:26

简单的步骤

brew services stop mysql
brew uninstall mysql

#this will delete all your local databases! (comment credit: Rod)
rm -R /usr/local/var/mysql

brew install mysql@5.7
brew services start mysql@5.7
brew link mysql@5.7 --force

步骤如下

  1. 搜索,确认版本存在
  2. 安装
  3. 确认安装成功
  4. 修改密码
  5. 修改远程登录权限
# 搜索,找到版本
brew search mysql

# 安装
brew install mysql@5.7

添加 link

brew link --force mysql@5.7      // 链接
brew services start mysql@5.7 // 启动服务

brew services stop mysql@5.7     //停止
brew services restart mysql@5.7 //重启

重要路径

# 安装路径
/usr/local/opt/mysql@5.7

# 控制命令
cd /usr/local/opt/mysql@5.7/support-files
./mysql.server start

让远程用户可以访问

UPDATE `mysql`.`user` SET `Host` = '%' WHERE `Host` = 'localhost' AND `User` = 'root';
flush privileges;

将密码修改为123456

UPDATE `mysql`.`user` SET password=password('123456') WHERE user='root';
flush privileges;

参考