1.安装mysql,并修改root密码为root
# 安装mysql,默认8.0以上
brew install mysql
# 设置mysql开机启动
#(1)首先确认~/Library/LaunchAgents目录存不存在,若存在则无需创建
#(2)建立软链接
#(3)设置自启动
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# 启动mysql
mysql.server start
# 进入服务,无需密码,直接回车
mysql -uroot
# 给root设置密码“root”
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
#退出重新进入就需要输入密码“root”
2.创建用户并授权
首先通过root登录数据库
# 创建用户
create user 'test'@'%' identified by '123123';
# 再进行授权
grant all privileges on *.* to 'test'@'%' with grant option;
#刷新权限
FLUSH PRIVILEGES;
# 退出root用户,使用test用户 登录数据库
mysql -utest -p
# 授权本地/