I have a very simple csv file having 3 columns having names 'a', 'b', 'c' of integer types having 5 columns. I want to import this data into SQL server in a database with pymysql. can somebody provide me the code for this? Also is PHPMyAdmin is required to do this?
This is my actual code:
import pymysql
f = open(r"a.csv", "r")
fString = f.read()
print(fString)
fList = []
for line in fString.split('\n'):
fList.append(line.split(','))
del(fList[0])
conn = pymysql.connect(host='localhost', user='root',
password='ajit2910@', database='mydatabase')
cur = conn.cursor()
cur.execute('CREATE TABLE jogi4(a INT,b INT,c INT)')
for i in range(len(fList)-1):
sqlquery = "INSERT INTO jogi3(a,b,c) VALUES(%s,%s,%s)"
cur.execute(sqlquery, (fList[i][0], fList[i][1], fList[i][2])) conn.close()