Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

mysql - Why don't I have access to the database from aws lambda but have from a local computer with the same login data?

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

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)

and got an error 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.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 hm why DB name is undefined ?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...