vim /etc/my.cnf
[mydqld]下面追加一行
skip-grant-tables
然后执行
mysql -u root
重新设置密码
use mysql; update user set authentication_string = password ( '新密码' ) where user = 'root' ; update user set Password=password('新密码') where user='root'; flush privileges; exit;
删除skip-grant-tables
重启mysql后,再次执行
mysql -u root -p
更新权限
set password for 'root'@'localhost'=password('新密码'); set password for 'root'@'127.0.0.1'=password('新密码'); grant all privileges on *.* to 'root'@'%' identified by '新密码' with grant option; flush privileges; exit;
重启mysql