Python / MySQL:表没有得到更新

我正在从一个Excel工作表中提取数据并将数据存入数据库的学校项目。 运行下面的代码并运行SQL命令SELECT * FROM items后,它将返回“空集”。 我究竟做错了什么? 我在这里先向您的帮助表示感谢!

import openpyxl import MySQLdb as mdb db = mdb.connect('localhost', 'root', 'TRM4611', 'practice') cur = db.cursor() wb_choice = input('What workbook would you like to use?\n--> ') wb = openpyxl.load_workbook(wb_choice + '.xlsx') all_sheets = wb.get_sheet_names() with db: for sheet in all_sheets: current_sheet = wb.get_sheet_by_name(sheet) print ('\nCurrent Sheet: ' + current_sheet.title) for i in range(current_sheet.max_column): for cellObj in current_sheet.columns[i]: if i == 0: cur.execute("INSERT INTO items(Date) VALUES(%s)", (cellObj.value,)) if i == 1: cur.execute("INSERT INTO items(Fruit) VALUES(%s)", (cellObj.value,)) if i == 2: cur.execute("INSERT INTO items(Quantity) VALUES(%s)", (cellObj.value,)) print (cellObj.coordinate, cellObj.value) print ('--- END OF ROW ---') 

您错过了提交,您必须在您的INSERT结束时提交查询

 db.commit()