来自python脚本插入行的MySQL使用pymysql失败

时间:2017-02-14 09:29:04

标签: python mysql

我的代码很简单,如下所示。我从MySQL工作台检查时,create table是正确的。但根本没有记录。任何人都可以教我为什么?我检查了SQL行在语法上是否正确。

import pymysql

conn = pymysql.connect(host='localhost', port=3306, user='root',    passwd='123456', db='db_name')
cur = conn.cursor()
test_line = "test line"
sqlStr = """ create table test_table 
    (
        id INT primary KEY auto_increment,
        name varchar(127) not null,        
        lastUpdateTime timestamp default current_timestamp on update current_timestamp,
        firstUpdateTime timestamp null
    ) """
if conn.open:
    print("trace")
    cur.execute(sqlStr)
    cur.execute(""" insert into test_table(name, firstUpdateTime ) 
        values('test', '2017-02-14 00:00:00') """)
    print(cur.description)
    print()
    print()
    for row in cur:
        print(row)
    print("trace end") 

cur.close()
conn.close()

0 个答案:

没有答案