mysql root用户Linux无法登录,一直拒绝
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using
password: YES)
百度了很久,之前由于远端无法访问mysql,将localhost修改过%,以为是这个问题,但是后来发现并不是。
mysql -uroot -p123 -h 127.0.0.1
通过该命令可以登录mysql,于是推测是授权问题
如果该命令也无法登录,更改my.conf文件。
Linux系统是在:/etc/my.cnf
在[mysqld]下添加
skip-grant-tables
重启后即可登录,问题解决后记得将该行注释掉再重启mysql。
于是成功登录mysql
use mysql;
show grants for root@localhost;
果然没有授权,直接授权
grant all privileges on . to ‘root’@‘localhost’ identified by
‘123’;
123是root登录的密码。
重新登录OK,问题解决。