1、系統環境
使用的是centos7系統,安裝Mysql8
2、修改配置文件
/etc/my.cnf文件
mysqld下添加 skip-grant-tables
3、重啓mysql服務
systemctl restart mysqld
4、修改密碼
(1)首先清空root用戶的authentication_string字段
authentication_string字段爲密碼,plugin爲加密方式
清空密碼字段,則密碼爲空。
清理完成後:
(2)退出mysql登錄
(3)注視掉 skip-grant-tables
(4)重啓Mysql服務
systemctl restart mysqld
(5)免密登錄
mysql -u root -p
(6)修改密碼
密碼要有大寫小寫字母特殊字符,還要求長度。