首页 > 解决方案 > 是否可以将本地 django 项目连接到在 AWS EC2 上运行的 MySql?如何?

问题描述

我尝试了什么:

{
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbtest',
        'USER': 'root',
        'HOST': '{IPv4 Public IP of the Instance}',
        'PASSWORD': 'password',
}

现在当我运行python manage.py runserver它给我错误

django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'xxx.xx.xxx.xxx' (using password: YES)")

然后,我还使用以下命令授予了该特定 IP 的所有权限:GRANT ALL PRIVILEGES ON *.* TO 'root'@'xxx.xx.xxx.xxx' WITH GRANT OPTION;

仍然没有运气。同样的错误。

标签: mysqldjangoamazon-ec2mysql-pythondjango-mysql

解决方案


您还必须设置 MySQL 配置以允许它在 mysqld.cnf 文件中接受远程连接添加更改以下值。

[mysqld]
bind-address    = 0.0.0.0
# skip-networking

然后重启 MySQL 服务。

并且您还必须在 EC2 实例的安全组中添加应用程序端口


推荐阅读