MySQL 8.0 重置密码
1. 关闭数据库
并重新用跳过验证的安全模式启动
mysql.server stop
mysqld_safe --skip-grant-tables
2. 数据库操作
新开一个窗口
mysql -uroot -p # 不用输入密码,直接按 Enter
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
其他
其他方式更改密码
mysql -uroot -p # 不用输入密码,直接按 Enter
use mysql;
ALTER user 'root'@'localhost' IDENTIFIED BY 'Qian123#' # 不更改其加密方式
# 或
update user set authentication_string="" where user="root"; # 密码设置为空
没有 root 用户时
mysql -uroot -p # 不用输入密码,直接按 Enter
use mysql;
select host, user, authentication_string, plugin from user;
flush privileges;
drop user 'root@localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY '密码';
GRANT all privileges ON *.* TO 'root'@'localhost';
update mysql.user set Grant_priv='Y',Super_priv='Y' where user = 'root' and host = '%';
3. 操作完毕
重启数据库
mysql.server restart