## 搜索可用版本
brew search mysql
## 安装制定版本
brew install mysql@8.0
## 重点需要关注的安装日志如下
==> Installing mysql@8.0
==> Pouring mysql@8.0-8.0.36_1.sonoma.bottle.tar.gz
==> /usr/local/Cellar/mysql@8.0/8.0.36_1/bin/mysqld --initialize-insecure --user=cookie. --basedir=/usr/local/Cellar/mysql@8.0/8.0
==> Caveats
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 -u root
mysql@8.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have mysql@8.0 first in your PATH, run:
echo 'export PATH="/usr/local/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql@8.0 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@8.0/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@8.0/include"
To start mysql@8.0 now and restart at login:
brew services start mysql@8.0
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@8.0/bin/mysqld_safe --datadir\=/usr/local/var/mysql
==> Summary
🍺 /usr/local/Cellar/mysql@8.0/8.0.36_1: 318 files, 301.2MB
==> Running `brew cleanup mysql@8.0`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> mysql@8.0
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 -u root
mysql@8.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have mysql@8.0 first in your PATH, run:
echo 'export PATH="/usr/local/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql@8.0 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@8.0/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@8.0/include"
To start mysql@8.0 now and restart at login:
brew services start mysql@8.0
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@8.0/bin/mysqld_safe --datadir\=/usr/local/var/mysql
## 解析日志得出:
## 安装目录
ll /usr/local/Cellar/mysql@8.0/8.0.36_1/bin/mysqld
## 配置 mysql 环境变量
echo 'export PATH="/usr/local/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/usr/local/opt/mysql@8.0/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/usr/local/opt/mysql@8.0/include"' >> ~/.zshrc
source ~/.zshrc
## 启动mysql
brew services start mysql@8.0
## 配置 root 用户密码:Root@123
mysql_secure_installation