改表法:把host地址改为%
use mysql;
update user set host = '%' where user = 'root'and host="127.0.0.1" ; FLUSH PRIVILEGES;
2、重新建立一个用户
1、把原user表导出一份来
mysqldump -w"User='root'" -uroot -p mysql user>/home/jksong/user.sql
2、修复其中的一条为 User='jksong' , Host='%', 然后插入user表, 不能复用下面的sql,不同版本sql可能会不同
INSERT INTO `user` VALUES ('%','jksong','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);
3、执行
FLUSH PRIVILEGES;
修改密码:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
update user set password=password("520") where user="root";