首先若Mac上没有安装Java JDK,那么先安装Java JDK成功后再安装MySQL。
安装Java JDK 请参考链接:https://www.jianshu.com/p/6fce43a30173
或:https://jingyan.baidu.com/article/908080221f3cfefd91c80fbf.html
1、MySQL下载地址:https://www.mysql.com/downloads/
下载最新的即可:
2、安装:全部默认即可,然后输入电脑密码,输入数据库root用户密码,确定即可。
3、配置环境变量:
(1)打开终端编辑.bash_profile:$ vim ~/.bash_profile
(2)插入 export PATH=$PATH:/usr/local/mysql/bin
(3)保存并退出编辑:$ Esc $ :w! $ :q!
(4)启用路径:$source ~/.bash_profile
(5)检测配置是否成功:$ echo $PATH (配置成功会输出的路径中会包含之前配置的路径)
4、终端启动/关闭mysql
$ sudo /usr/local/mysql/support-files/mysql.server start
$ sudo /usr/local/mysql/support-files/mysql.server stop
5、重置密码
(1)关闭服务:$ sudo /usr/local/mysql/support-files/mysql.server stop
(2)进入目录:$ cd /usr/local/mysql/bin
(3)获取权限:$ sudo su
(4)重置密码并重启服务:$ ./mysqld_safe --skip-grant-tables
(5)登录服务:$ mysql
(6)获取修改密码权限:$ flush privileges
(7)设置新密码:$ set password for 'root'@'localhost'='newPassword'