python连接没有在数据库中保存数据

Yun*_*nus 1 python mysql

我已经成功连接到 python 中的数据库,但它没有保存我提供的数据。这是代码:

    try:
    connection = MySQLdb.connect(host="localhost",user="root",passwd="",db="traffic_alert")
except Exception as e:
    print('Not connected')


   cursor = connection.cursor()
cursor.execute("insert into data (main_status,extracted_info,time) values (%s,%s,%s)",[sentence,final_result,time])
print(sentence)
print(final_result)
print(time)
Run Code Online (Sandbox Code Playgroud)

它可以成功打印句子、final_result 和 time,但不能将它们保存在 database.sentence、final_result 和 time 中小于 50 个字符。我在 mysql 中手动创建了这些行的数据库:

id -> auto_increment,pk
main_status -> varchar(255)
extracted_info -> varchar(255)
seen  -> int(10),Null=True
time ->varchar(255)
Run Code Online (Sandbox Code Playgroud)

Yas*_*kar 5

connection.commit()
Run Code Online (Sandbox Code Playgroud)

在 cursor.execute 之后