1、修改MySQL数据库配置文件
#在/etc/my.cnf增加skip-grant-tables
#重启数据库systemctl restart mysqld
#添加后登录数据库不需要密码
2、登录MySQL数据库
#mysql
3、重置root密码
#update mysql.user set authentication_string=password("new-passwd") where User='root' and Host='localhost'; #new-passwd:新密码 localhost:MySQL主机地址
#flush privileges; #重置
4、注释MySQL配置文件增加内容
#skip-grant-tables
5、重启数据库,用新密码登录
#systemctl restart mysqld
#mysql -uroot -p