MySQL修改root密码

首先以管理员身份运行cmd设置停止mysql数据库,修改my.ini配置文件的时候,添加skip-grant-tables  #跳过数据库权限验证

然后,根据下面命令重启数据库,在终端输入如下命令:

注意:旧版的mysql的存储密码的字段是“password”,现在是“authentication_string”。

C:>net stop mysql
MySQL 服务正在停止.
MySQL 服务已成功停止。


C:\Windows\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。


C:\Windows\system32>mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.32 MySQL Community Server (GPL)

mysql> use mysql;
Database changed
mysql> update user set password=password("输入你想要的密码,可以为空") where user="root";
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update user set authentication_string='输入你想要的密码,可以为空' where user="root";
Query OK, 2 rows affected (0.10 sec)
Rows matched: 2 Changed: 2 Warnings: 0

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

mysql> quit;
Bye

posted @ 2021-05-07 18:03  Leise  阅读(173)  评论(0编辑  收藏  举报