首页 > 解决方案 > 当我在 amazon-ec2 中访问 mysqldb 时,远程访问被拒绝。(1045,“用户'user-name'@'some-ip'的访问被拒绝)

问题描述

我在 AWS 中创建了一个 ec2 用户服务器。然后安装mysql我已经用谷歌搜索了这个问题然后我检查我做得很好。

# mysql --version
mysql  Ver 14.14 Distrib 5.5.58, for Linux (x86_64) using readline 5.1

首先,设置 aws 入站 0.0.0.0:3306

# netstat -tln

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN 

其次,为 0.0.0.0 创建 mysql 用户 'yj'。(我也试过'%'。但它不起作用。所以我也试过'0.0.0.0'。)

mysql> select host, user, password from mysql.user;

+------------------+------+-------------------------------------------+
| host             | user | password                                  |
+------------------+------+-------------------------------------------+
| localhost        | root | *some-password                            |
| ip-172-31-86-160 | root |                                           |
| 127.0.0.1        | root |                                           |
| ::1              | root |                                           |
| localhost        |      |                                           |
| ip-172-31-86-160 |      |                                           |
| 0.0.0.0          | yj   | *some-password                            |
+------------------+------+-------------------------------------------+

第三,检查/etc/my.cnf文件。

# cat /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

人们说修改bind-address=127.0.0.1bind-address=0.0.0.0. 但是我的 .cnf 文件没有任何绑定地址。所以我试图在/etc/mysql/mysql.conf.d/etc/mysql.conf等等中找到另一个conf文件。但是没有/etc/my.cnf文件就没有什么。

你能告诉我有什么我想念的吗?

标签: mysqlamazon-ec2

解决方案


[解决了]

我解决了因为学校无线网络的问题。也许有什么……你知道的。

所以连接被拒绝的消息'Connection failed: Access denied for user 'yj'@'some-ip'。和'some-ip'我使用的不同。所以我使用该 ip 创建用户。现在,运作良好。

我希望这个对你有用。


推荐阅读