linux MySQL出现错误的一些常见解决办法

1045:

  描述:

    用户被数据库拒绝访问了,我们应该为你的数据库开辟权限。

  解决办法:

    1.登录数据库输入linux指令

     

mysql -uroot -padmin

    2.查询用户和权限

select host,user from user;

    3.远程mysql服务器,需要增加普通权限的用户

grant select,update,insert,delete on mas.* to root@localhost identified by "admin";
#新建用户root,并且只允许该用户在本地(localhost)登录,密码是admin,并且赋予它对mas库中所有表select,update,insert的权限。我们在这有一个mas库,所以用mas.*代表mas库下的所有表。 现在该root用户,已经可以登录mysql了,但是也还是只能本地登录。

    4.若要想root用户可以远程登录mysql,则还需要以下命令

update user set host = '%' where user = 'root';

    5.也可以直接给用户权限

GRANT ALL ON *.* TO 'root'@'localhost'; #grant all on *.* to 用户名@"%" identified by "密码";

flush privileges; #刷新权限
原文地址:https://www.cnblogs.com/peijyStudy/p/13501036.html