pymysql.err.InternalError: (1049, “Unknown database”)

Question:

I want to connect MySQL RDS DB using python from raspberrypi.(i want to get seq from MySQL table ‘face’ using select query.)

and I have an error but i can not fix it.

This is rds mysql connection code:

rds_config:

and This is traceback:

i alread added ip address in vpc security group and public access is on.
it was possible to connect through mysql cli or workbench.

can anyone help me?

Answer:

tl;dr you need to create bsb-rd. Execute this command: create database bsb-rds either with cur.execute() in python or in your favorite sql cli.

If you get this error, good news! You can connect to your RDS instance. This means you have the security group set up right, the host url, username, password and port are all correct! What this error is telling you is that your database bsb-rds does not exist on your RDS instance. If you have just made the RDS instance it is probably because you have not created the database yet. So create it!

Here are two ways to do this

mysql cli

In your terminal run

mysql --host=the_host_address user=your_user_name --password=your_password

Then inside the mysql shell execute

create database bsb-rd;

Now try your code again!

Python with pymysql

I came to this page looking for a solution and didn’t get it. I eventually found the answer and now share what helped me.

Leave a Reply