I have some data in a tab-delimited file that i'm trying to insert into an SQL database. Here is my code
import csv
import MySQLdb
new_db = MySQLdb.connect(host='localhost',user='me')
cursor = new_db.cursor()
cursor.execute('create database if not exists my_database')
maketablestr = """CREATE TABLE info (Disease VARCHAR(10), NCBI Acc. Number VARCHAR(10) ,Length VARCHAR(10), Sequence VARCHAR(10));"""
cursor.execute(maketablestr)
new_db.commit()
tsv_read = csv.reader(file('marfan.tsv'), delimiter = '\t')
for row in tsv_read:
cursor.execute('INSERT INTO info(Disease, NCBI Acc. Number, Length, Sequence ) VALUES(%s, %s, %s, %s)', row)
new_db.commit()
cursor.close()
new_db.close()
print("Database updated")
When I run the code, it gives me the error 1046 'No Database Selected'. I'm a little confused as to why I'm getting this error since the code that I wrote is mostly taken from others who are trying to do the same thing as me.