MySQL重置密码

MySQL重置密码

1.打开一个dos窗口 停止MySQL服务

net stop mysql

2.无密码启动

mysql --console --skip-grant-tables --shared-memory

3.重新开一个dos窗口,无密码登录进入,清空密码

mysql -u root
update mysql.user set authentication_string='' where user='root' and host='localhost';

4.退出开启的两个dos窗口,重新再打开一个 重启MySQL

mysql start mysql

5.再次无密码登录进去 重新设置密码

mysql -u root
切换到MySQL库
use mysql;
设置密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
刷新权限
FLUSH PRIVILEGES;
退出
quit;

现在就密码重置好了!

对于MySQL5.7的版本,因为在user表中没有password字段,所以一直使用如下代码,来修改root密码

use mysql; 
update user set authentication_string = password(“root”) where user = “root”;

查阅后知道在mysql5.7.9以后废弃了password字段和password函数;authentication_string:字段表示用户密码。

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;

出现以上问题需要执行

刷新权限
flush privileges

你可能感兴趣的:(mysql,数据库,database)