MySQL for Mac 5.7.x 版本忘记密码修改root密码

1.安装mysql

2.命名别名:

vim ~/.bash_profile
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin

3.修改密码(版本5.7.x):

通过 –skip-grant-tables的方式启动mysqld_safe ,这个模式可以绕过mysql授权。

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

之后新启动一个终端,进入mysql:

sudo /usr/local/mysql/bin/mysql -u root

在mysql.user中以前版本会有一个字段password,但是现在替换成了authentication_string

进入mysql之后:

mysql> update mysql.user set authentication_string=PASSWORD('123') where user='root';
Query OK, 1 row affected, 1 warning (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> quit

这时候Myqsl密码已经修改完了,我们把上面的mysqld进程干掉,通过正常途径起Mysqld服务

mysql -u root -p

mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql> set password for root@localhost=password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+——————–+
4 rows in set (0.01 sec)

修改成功!

 

posted @ 2017-03-24 20:53  WangC.W  阅读(480)  评论(0编辑  收藏  举报