当我在amazon-ec2中访问mysqldb时,远程访问被拒绝。 (1045,“访问被拒绝用户'用户名'''some-ip')

时间:2018-05-20 14:33:00

标签: mysql amazon-ec2

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

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

首先,设置aws inbound 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.1修改为bind-address=0.0.0.0。但我的.cnf文件没有任何绑定地址。所以我试图在/etc/mysql/mysql.conf.d/etc/mysql.conf中找到另一个配置文件,依此类推。但没有/etc/my.cnf文件。

你能告诉我有什么我错过的吗?

2 个答案:

答案 0 :(得分:0)

你有没有尝试过:

CREATE USER 'yj'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'yj'@'localhost';
FLUSH PRIVILEGES;

您可以通过以下方式检查用户权限:

SHOW GRANTS yj;

尝试将'localhost'替换为您实际使用的主机,我想是的:

'0.0.0.0'

答案 1 :(得分:0)

[解决]

我解决了问题,因为有学校的Wi-Fi。也许有什么......你知道。

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

我希望这会有所帮助。

相关问题