解决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

4

至此,MySQL初始密码就设置好了。


你可能感兴趣的:(Java,mysql,mac,mysql,mysql设置密码)