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


  1. 先到mysql官网上下载dmg格式安装包,进行安装。
  2. 安装完后,命别名:
vim ~/.bash_profile

alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
  1. 修改MySQL密码(版本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)

mysql>

你可能感兴趣的:(MySQL for Mac 5.7.x 版本修改root密码)