0

Data is not uploaded to mysql-workbench

I checked mysql-workbench

import xlrd
import pymysql

book = xlrd.open_workbook("c:/Temp/exportimport201006.xls")
sheet = book.sheet_by_name("201006")

database = pymysql.connect(host = 'xxx', user = 'xxx', password = 'xxx', db = 'xxx')
cursor = database.cursor()
query = """INSERT INTO exportimport (year, hscode, expwgt, expdlr, impwgt, impdlr, balpayments) VALUES (%s, %s, %s, %s, %s, %s, %s)"""

for r in range(2, sheet.nrows):
    year = sheet.cell(r,0).value
    hscode = sheet.cell(r,1).value
    expwgt = sheet.cell(r,2).value
    expdlr = sheet.cell(r,3).value
    impwgt = sheet.cell(r,4).value
    impdlr = sheet.cell(r,5).value
    balpayments = sheet.cell(r,6).value

    values = (year,hscode,expwgt,expdlr,impwgt,impdlr,balpayments)
    cursor.execute(query, values)

database.close()

It doesn't finish nevertheless data is not large

Which part is wrong?

I'm python beginner

1
  • Now tell me in what sense this python code relates to MySQL Workbench? Commented Oct 14, 2019 at 7:18

1 Answer 1

1

It seems you are missing the commit operation after cursor.execute.

Coding like this:

database.commit()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.