我用到的数据库是mysql8
环境是centos7
service mysqld stop
vi /etc/my.cof
在最下面加上skip-grant-tables
service mysqld start
mysql -u root -p密码为空,直接回车
use mysql;
select host, user, authentication_string, plugin from user;将authentication_string字段设置为空,就是把密码设置为空
update user set authentication_string=‘‘ where user=‘root‘;
/etc/mycnf
最后加的哪一行(dd)删除service mysqld stop
service mysqld start
mysql -u root -p
passwd 直接回车就可以登陆
ALTER user ‘root‘@‘localhost‘ IDENTIFIED BY ‘Mynameis7#‘
原文:https://www.cnblogs.com/zhuyeshen/p/12883435.html