一,忘记mysql的root密码
方法流程:
1.关闭正在运行的MySQL服务。
2.打开DOS窗口,转到mysql\bin目录。
3.输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。
4.再开一个DOS窗口(因为刚才那个DOS窗口已经不能动了),输入mysql回车,如果成功,将出现MySQL提示符 >。
5.连接权限数据库: use mysql; 。
6.改密码:update user set password=password("新密码") where user="root";(别忘了最后加分号) 。
7.刷新权限(必须步骤):flush privileges;
8.退出mysql quit;
第一个DOS界面
[root@localhost bin]# mysqld --skip-grant-tables 2022-10-21T13:41:43.458128Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2022-10-21T13:41:43.458200Z 0 [Note] --secure-file-priv is set to NULL. Operations related .......... 2022-10-21T13:41:43.548725Z 0 [Note] Plugin 'FEDERATED' is disabled. 2022-10-21T13:41:43.551203Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
开启第二个DOS界面
[root@localhost ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.20 MySQL Community Server (GPL) mysql> use mysql; mysql> update user set password=password("新密码") where user="root"; mysql> flush privileges; mysql> quit;
二,报错 ERROR 1054 (42S22): Unknown column 'password' in 'field list'
使用上面的修改密码的方式,提示错误
mysql> update user set password=PASSWORD('要修改的密码') where user='root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list'
后来去MySQL官网查了一下手册,发现MySQL5.7版本后,password这个字段被改成 authentication_string,OK原因出来,那么我去修改一下字段就OK了,所以正确的命令应该是这样的
mysql> update user set authentication_string=password("您要修改的密码") where user="root";
刷新mysql权限
mysql> flush privileges;