mac apple silicon M2 安装mysql5.7

发布时间 2023-05-31 09:58:21作者: vx_guanchaoguo0

1、brew安装MySQL

// 1. 若不考虑版本直接执行以下命令
brew install mysql
// 2. 若要选择版本只要加上@版本即可,例如
brew install mysql@5.7 
// 3. 安装完后启动mysql
 brew services start mysql@5.7
// 4. 若服务未启动就会出现以下错误
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
// 5. 若要关闭mysql
 brew services stop mysql@5.7
// 6. 看到提示success则表示启动成功
Starting MySQL
. SUCCESS! 
// 7. 现在登录mysql,默认情况下免密登录
mysql -u root
// 8. 修改root密码,这是5.7的修改方法
alter user 'root'@'localhost' identified with mysql_native_password by 'root';
// 9. 回车后有提示,则表示修改成功
Query OK, 0 rows affected (0.00 sec)
// 10. 接着退出mysql
exit;
// 11. 最后重新登录
mysql -u root -p

提示信息

// We've installed your MySQL database without a root password. To secure it run:
 mysql_secure_installation

//  MySQL is configured to only allow connections from localhost by default

//  To connect run:
    mysql -uroot

//  mysql@5.7 is keg-only, which means it was not symlinked into /opt/homebrew,
//   because this is an alternate version of another formula.

// If you need to have mysql@5.7 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

// For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

// For pkg-config to find mysql@5.7 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql@5.7/lib/pkgconfig"

// To start mysql@5.7 now and restart at login:
  brew services start mysql@5.7