简体   繁体   English

如何将开发阶段的Django Web应用程序连接到现有的AWS MySQL数据库?

[英]How do I connect development-stage Django web app to an existing AWS MySQL database?

Short question - How do I connect to an existing Amazon Web Services MySQL database from my development-stage Django web app? 简短的问题-如何从开发阶段的Django Web应用程序连接到现有的Amazon Web Services MySQL数据库?

Context: 语境:

I am working on creating a webpage using the Django framework. 我正在使用Django框架创建网页。

I've successfully created an AWS MySQL RDS database and have imported my data and connected to it successfully via MySQL Workbench. 我已经成功创建了一个AWS MySQL RDS数据库,并导入了我的数据,并已通过MySQL Workbench成功连接到它。

I am now at a point where I am trying to connect to the database from my Django app. 现在,我正试图从Django应用程序连接到数据库。 I will require read-only functionality from the database from within the app... I will not be writing any new info to the database. 我将需要从应用程序中获取数据库的只读功能...我将不会向数据库写入任何新信息。 Furthermore, I am trying to do this within a development environment, as I am not even close to anything production worthy (ie, I am working locally off of my laptop). 此外,我试图在开发环境中执行此操作,因为我什至没有接近任何有价值的产品(即,我正在使用笔记本电脑在本地工作)。

I've added the AWS database information to my Django settings.py file, and based on my research, to generate the requisite models I'll need to utilize Django's 'inspectdb' utility. 我已将AWS数据库信息添加到我的Django settings.py文件中,并根据我的研究生成了使用Django的'inspectdb'实用程序所需的必要模型。 I've tried that, and the resulting error received was: 我已经尝试过了,收到的结果错误是:

django.db.utils.OperationalError: (1045, u"Access denied for user '[ my username was here, which actually showed my literal first name rather than any type of username that was established by AWS ]'@'pool-[ my IP address was here ].nwrknj.fios.verizon.net' django.db.utils.OperationalError:(1045,u“拒绝访问用户'[ 我的用户名在这里,实际上显示了我的字面名字,而不是由AWS建立的任何类型的用户名 ]'@'pool- [ 我IP地址在这里 ] .nwrknj.fios.verizon.net'

Has anyone else experienced this issue and identified a solution? 是否还有其他人遇到此问题并确定了解决方案?

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    '[removed]': {
          'NAME': '[removed]',
          'ENGINE': 'django.db.backends.mysql',
          'USERNAME': '[removed]',
          'PASSWORD': '[removed]',
          'HOST': '[removed].us-west-2.rds.amazonaws.com',
          'PORT': '3306'

Unless you have DATABASE_ROUTERS set to use an alternate database, everything in Django will use the default database. 除非您将DATABASE_ROUTERS设置为使用备用数据库,否则Django中的所有内容都将使用default数据库。 Get rid of the current ENGINE and NAME in default and move all the [removed] db info into default . 默认情况下摆脱当前的ENGINE和NAME并将所有[removed]数据库信息移到default

Also make sure that the AWS RDS port 3306 is open to your FIOS IP address. 还要确保您的FIOS IP地址已打开AWS RDS端口3306。 Ideally you would restrict it in AWS to only the actual servers (whether on AWS or elsewhere) but for now you may have to set a broad IP range to allow for your FIOS IP changing periodically during development. 理想情况下,您将在AWS中将其限制为仅实际服务器(无论是在AWS还是其他地方),但是现在您可能必须设置一个较大的IP范围,以允许您的FIOS IP在开发期间定期更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM