Skip to content

Instantly share code, notes, and snippets.

@theDreamer911
Last active March 4, 2021 20:57
Show Gist options
  • Save theDreamer911/5dd4cde6942365f645940109757d748e to your computer and use it in GitHub Desktop.
Save theDreamer911/5dd4cde6942365f645940109757d748e to your computer and use it in GitHub Desktop.
import MySQLdb
import csv
import sys
conn = MySQLdb.connect(host="127.0.0.1", user="root", password="", database="Fruit_Shop")
cursor = conn.cursor()
csv_data = csv.reader(open('products.csv'))
header = next(csv_data)
print('Importing the CSV Files')
for row in csv_data:
print(row)
cursor.execute(
"INSERT INTO product (id,name,price,stock) VALUES (%s, %s, %s, %s)", row)
conn.commit()
cursor.close()
print('Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment