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
为什么这不起作用?它的打印正确,但数据库仍为空。 我检查过数据库,看起来不错 所有详细信息均正确
最佳答案
您需要提交事务,或将自动提交设置为 True。
关于Python 未插入 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26274965/