场景:安装mysql5.7后使用xshell等远程访问工具登陆了root账户然后通过xshell等远程工具使用mysql密码(非临时密码)登陆mysql5.7,提示ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)。
解决方案:此问题是因为远程工具没有对mysql的本地账户的访问权限,所以需要用户登陆服务器,按如下操作:
#使用服务器而不是xshell等远程工具登陆mysql5.7(其他版本可能代码不一样)
mysql -u root -p
#然后输入mysql密码
#下面为mysql授权
#方法一:仅为本地用户授权
grant all privileges on *.* to root@'localhost' identified by '密码';
flush privileges;
#方法二:为所有用户授权
grant all privileges on *.* to root@'%' identified by '密码';
flush privileges;
#然后quit
quit
#此时使用xshell等远程工具登陆发现可以登陆成功