import codecs import dataset fr=codecs.open('c:/tmp/Queries.csv','r','utf-8') lines=fr.readlines() fr.close() db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4') table=db['hhh_gsc_imp'] for l in lines: # print(l) elmts=l.strip().split(',') print(elmts[0]) print(elmts[4]) try: table.insert({'query':elmts[0],'position':elmts[4]}) except: print('except')