语句#0中的SQL错误(1045):用户访问被拒绝' root' @'

时间:2014-11-19 18:05:30

标签: amazon-ec2 centos mysql-5.1

尝试使用Heidi在本地root访问我们的EC2实例,在客户端使用外部IP生成错误消息:

  

语句#0中的SQL错误(1045):拒绝用户访问   '根' @' internal.host.net' (使用密码:是)

连接内部IP会产生不同的错误:

  

语句#0中的SQL错误(2003):无法连接到MySQL服务器   ' 10.0.5.152' (10060)

/etc/hosts

127.0.0.1 localhost

没有内部IP线,也没有EC2外部主机名的行:

  

10.0.5.152主机名

+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*D0**********' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
user
root localhost
root ip-10-0-5-152
root 127.0.0.1
     localhost
     ip-10.0.5.152

我执行的命令是:

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

1 个答案:

答案 0 :(得分:1)

我面临类似的问题,所以为此我通过授予所有权限创建新用户然后我连接到ec2-instance并且它允许我在那之后连接,你也可以这样做,

以下是步骤。

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'username'@'your_public_ip' WITH GRANT OPTION;

CREATE USER 'username'@'%' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;