我有以下Python代碼:Python的MySQL錯誤1064插入的時間字符串
now = time.strftime('%Y-%m-%d %H:%M:%S')
#now = datetime.datetime.now()
query = """INSERT INTO bandwidth_by_second (current_time, down, up) VALUES (%s, %s, %s)"""
data = (now, 1.0, 2.0)
cursor.execute(query, data)
我給這家表架構是:
- CURRENT_TIME - DATATIME
- 下來 - 雙
- 了 - double
When運行此,我得到以下錯誤:
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'current_time, down, up) VALUES ('2014-10-27 18:29:32', 1, 1)' at line 1")
我曾以爲我已經格式化的日期時間不對,但this post並非如此。
這是怎麼回事?
我看到其他答案表明同樣的事情。當我這樣做'query =「」「INSERT INTO bandwidth_by_second(current_time,down,up)VALUES('%s',%s,%s)」「」',結果的錯誤看起來像'(1064,「You have在你的SQL語法中出錯;查看與你的MySQL服務器版本相對應的手冊,以在'current_time,down,up'附近使用正確的語法)VALUES(''2014-10-28 08:11:52.306849'', 1)'在第1行「) – 2014-10-28 07:13:06