Linux 上重置 MySQL root 密码的标准流程:
第一步:停掉 MySQL
bash
systemctl stop mysql
# 或者
systemctl stop mysqld
第二步:跳过权限验证启动
bash
mysqld_safe --skip-grant-tables &
第三步:无密码登录进去改密码
bash
mysql -u root
进去之后执行:
sql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
FLUSH PRIVILEGES;
EXIT;
第四步:重启 MySQL
bash
systemctl stop mysqld
systemctl start mysqld
# 或
systemctl restart mysql
然后用新密码登录验证:
bash
mysql -u root -p
如果第二步 mysqld_safe 找不到命令,试试:
bash
mysqld --skip-grant-tables --skip-networking &
个人微信:ssevening