为什么我不能从aws lambda访问数据库,而从具有相同登录数据的本地计算机访问? [英] Why don't I have access to the database from aws lambda but have from a local computer with the same login data?
问题描述
我在Amazon RDS中创建了一个新的Mysql数据库,在本地计算机上,我可以通过控制台进行访问
I created a new Mysql database in Amazon RDS, and on my local computer I get access through the console
mysql -u username -p -h test.c2nfdg67dbdpb.us-east-1.rds.amazonaws.com
现在,我尝试使用python和pymysql模块通过Aws Lamda连接
Now I try to connect via Aws Lamda using python and pymysql module
rds_host = "test.c2nfdg67dbdpb.us-east-1.rds.amazonaws.com"
name = 'username'
password = 'pass'
db_name = 'dbtest'
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
并出现错误ERROR] 2019-11-20T14:30:05.261Z 7b1ed2e0-03ba-4c62-9525-22d84582f (1049, "Unknown database 'dbtest'")
奇怪的是,我根本没有通过本地控制台使用数据库名称,并且可以访问.
It seems strange that I don't use the database name at all through the local console and I get access.
p.s.我在本地控制台上运行show databases;
,在数据库列表中看不到dbtest
.我很困惑,因为当我创建新数据库时,我输入了一个名称,但是只列出了默认数据库.那我要连接什么?
p.s.I run show databases;
on local console and cant see dbtest
in databaselist. I was confused because when I created the new database, I entered a name, but only default databases are listed. What am I connected to then?
p.s.s 嗯,为什么数据库名称未定义?
p.s.s hm why DB name is undefined ?
推荐答案
您的代码明确尝试连接名为dbtest
的特定数据库.与您的mysql客户端(无需选择数据库即可连接)相反,它将连接到该数据库或失败.显然,数据库已丢失,因为您已验证show databases
结果不包括dbtest
.
Your code explicitly tries to connect a specific database named dbtest
. It will either connect to this database or fail, contrary to your mysql client which can connect without a database selection. Clearly, the database is missing, since you verified that show databases
results does not include dbtest
.
然后唯一可能的解释是数据库从未创建过.
Then only possible explanation is that the database was never created.
这篇关于为什么我不能从aws lambda访问数据库,而从具有相同登录数据的本地计算机访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!