安装步骤:
1.直接在命令行使用brew进行安装
brew install mysql
自动安装最近版本
brew install mysql@5.7
安装mysql5.7版本
1.1 安装过程中可能存在权限问题,提示如下:
Error: The following directories are not writable by your user:
/usr/local/share/man/man8
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/man/man8
And make sure that your user has write permission.
chmod u+w /usr/local/share/man/man8
可以通过执行以下命令解决:
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
2.等待安装完成之后配置mysql用户密码
可以通过运行以下命令来启动MySQL服务器(mac 重启后会重新启动mysql)
brew services start mysql
停止命令(执行后mac重启不会在自动启动mysql):
brew services stop mysql
以下命令也可以启动或是停止mysql,但计算机重新启动不会自动启动mysql
mysql.server start
mysql.server stop
安装好之后root用户默认是没有密码的
使用 brew services start mysql
启动mysql
使用 mysql -uroot -p
登陆mysql,如果提示输入密码,直接回车即可
使用 alter user 'root'@'localhost' identified by '123456';
修改密码
退出之后使用新密码登陆即可