在数据库配置文件my.cnf的[mysqld]下面添加skip-grant-tables,忽略授权表
vim /etc/my.cnf [mysqld] skip-grant-tables
[root@localhost etc]# /etc/init.d/mysqld restart Shutting down MySQL. SUCCESS! Starting MySQL. SUCCESS! #不输入密码直接回车 [root@localhost etc]# mysql -p
用不了grant语句改密码
mysql>update user set authentication_string = password('123456'), password_expired = 'N', password_last_changed = now() where User = 'root'; mysql>quit
删除数据库配置文件my.cnf的skip-grant-tables,并重启MySQL服务,然后用刚刚改好的密码登陆数据库