Python不插入MySQL

时间:2014-10-09 09:30:35

标签: python mysql

import MySQLdb
import time

try:
        db = MySQLdb.connect(host="", #your host, usually localhost
                     user="", #your username
                      passwd="", #your password
                      db="") #name of the data base
        cur = db.cursor()
except mysql.connector.Error as err:
    print("Something went wrong: {}".format(err))

SQL = "INSERT INTO TBL_PYTest (Time) VALUES (%s)"
Count = 0


while Count < 5:
        UTime =  int(time.time())
        print UTime
        cur.execute(SQL, (UTime))
        time.sleep(5)
        Count = Count + 1
        print Count

为什么这不起作用?它正确打印但数据库保持空白。 我检查了数据库,看起来很好 所有细节都是正确的

1 个答案:

答案 0 :(得分:3)

您需要提交您的交易,或将autocommit设置为True。