安装 mysql 数据库

安装 Mysql

搜索版本 :

brew search mysql

安装 Mysql :

brew install mysql@5.7

安装过程重要信息

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 /usr/local,
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="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
......

将 Mysql 添加到环境变量

echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

启动 Mysql

brew services start mysql@5.7 

测试 Mysql

mysql -uroot
show databases;

修改 Mysql 密码

# 连接数据库
mysql -u root
# 选择 mysql 库
use mysql
# 修改密码
update user set authentication_string=password('新密码') where user='root';
# 刷新权限
flush privileges;