编辑mysql配置文件 vim /etc/my.cnf 在其中添加skip-grant-tables 保存
重启mysql服务 # systemctl restart mysqld
使用无密码命令登录mysql数据库 #mysql
使用下面语句修改root密码 mysql> update mysql.user set authentication_string=password(‘新密码‘) where user=‘root‘; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql>quit
编辑mysql配置文件,将之前添加的skip-grant-tables去掉
重启mysql服务 # systemctl restart mysqld
#登录mysql mysql -u用户名 -p #输入密码
原文:https://www.cnblogs.com/u-damowang1/p/13185920.html