最近在迁移数据库时,登录phpMyAdmin出现了以下错误
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES)
网上搜索了很多方法都无法解决这个问题,为此还重装了数据库,教训惨痛。下面把解决方法记录一下。其实很简单,唉。。。。
首先登录mysql
mysql -u root -p
然后选择mysql数据库
use mysql;
查看user表
select host,user,authentication_string from user;

因为Mysql5.7以上版本不支持password字段,所以用的是authentication_string 字段。然后修改密码:
alter user'root'@'localhost' identified with mysql_native_password by '新密码';
或者
alter user'root'@'localhost' identified by '新密码';
最后执行
flush privileges;#立即生效
退出重新登录就可以了。
暂无评论...