1. 下载mysql for mac: https://dev.mysql.com/downloads/installer/
2. 双击mysql-5.7.17-macos10.12-x86_64.dmg进行解压, 双击mysql-5.7.17-macos10.12-x86_64.pkg进行安装
3. Continue -> Continue, Agree -> Install -> 输入管理员密码
4. 记录下来弹窗中的密码
5. 进入系统偏好设置, 找到mysql, 启动服务
6. 将mysql的命令添加到系统中
(1).进入/usr/local/mysql/bin,查看此目录下是否有mysql
(2).执行vim ~/.bash_profile
在该文件中添加mysql/bin的目录
PATH=$PATH:/usr/local/mysql/bin
添加完成后,按esc,然后输入wq保存。
(3).最后在命令行输入source ~/.bash_profile
7. 通过mysql -uroot -p登录mysql, 输入之前保存的密码
8. 重置mysql初始密码
二:如果忘记截图中的密码
一、第一步:停止MySQL服务。
可能在使用MySQLWorkBench之前,你就开启了MySQL服务,所以这里需要关闭MySQL服务。
关闭MySQL服务的操作:
苹果->系统偏好设置->最下边点MySQL 在弹出页面中 关闭mysql服务(点击stop mysql server
)
二、第二步:进入终端,指令重启MySQL服务。
0、打开终端:
1、输入指令1:(进入到mysql的bin目录下)
输入:cd /usr/local/mysql/bin/
2、输入指令2:
输入:sudo ./mysqld_safe --skip-grant-tables
3、输入指令2,会提示输入密码:(Mac账户的root用户密码)
4、输入密码后:会出现一堆提示:
Logging to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/ShiXiongweideMacBook-Pro.local.err'.
2017-06-17T06:35:38.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.18-macos10.12-x86_64/data
- 1
- 2
5、然后会发现,MySQL会自动重启。
附:第二步步骤,我这边终端上指令代码,罗列如下:
ShiXiongweideMacBook-Pro:~ shixiongwei$ cd /usr/local/mysql/bin/
ShiXiongweideMacBook-Pro:bin shixiongwei$ sudo ./mysqld_safe --skip-grant-tables
Password:
Logging to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/ShiXiongweideMacBook-Pro.local.err'.
2017-06-17T06:35:38.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.18-macos10.12-x86_64/data
- 1
- 2
- 3
- 4
- 5
- 6
第三步:另外开一个终端,设置MySQL密码。
0、另外再开一个终端:
1、输入指令1:(进入到mysql的bin目录下)
输入:cd /usr/local/mysql/bin/
2、输入指令2:
输入:./mysql
3、进入到mysql命令状态下:(mysql>
是mysql命令状态提示)
输入:mysql> FLUSH PRIVILEGES;
4、设置密码admin123
输入:mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('admin123');
附:第三步步骤,我这边终端上指令代码,罗列如下:
ShiXiongweideMacBook-Pro:~ shixiongwei$ cd /usr/local/mysql/bin/
ShiXiongweideMacBook-Pro:bin shixiongwei$ ./mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('admin123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
至此,MySQL初始密码就设置好了。