mac 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,会提示输入密码:(苹果账户的根用户密码)
输入密码后:会出现一堆提示:

Last login: Thu Jul  1 11:25:20 on ttys001
zsm@zsmdeMacBook-Pro ~ % cd /usr/local/mysql/bin/ 
zsm@zsmdeMacBook-Pro bin % sudo ./mysqld_safe --skip-grant-tables
Password:
210701 11:32:29 mysqld_safe Logging to '/usr/local/mysql-5.6.41-macos10.13-x86_64/data/zsmdeMacBook-Pro.local.err'.
210701 11:32:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.6.41-macos10.13-x86_64/data

5,然后会发现,MySQL的会自动重启。

第三步:另外开一个终端,设置MySQL的密码。

0,另外再开一个终端:
1,输入指令1 :(进入到的MySQL的仓目录下)
输入: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');

附:第三步步骤,我这边终端上指令代码,罗列如下:

Last login: Thu Jul  1 11:32:17 on ttys001
zsm@zsmdeMacBook-Pro bin % cd /usr/local/mysql/bin/
zsm@zsmdeMacBook-Pro bin % ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.6.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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('root');
Query OK, 0 rows affected (0.00 sec)

mysql> 

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

你可能感兴趣的:(mac mysql重设密码)