我在将datetime对象插入MySQL时遇到问题。没有错误消息,但我看不到插入的记录。我打印了插入的输出,它返回
1
now = datetime(2018, 8, 20, 11, 5, 3)
print now
conn = MySQLdb.connect(host=hostname, user=username, passwd=password, db=database)
cur = conn.cursor()
d = cur.execute('INSERT INTO mytable(begin_date, end_date, status) VALUES (%s,%s,%s)',(now,now,"success"))
print d
>>
2018-08-20 11:05:03
1
mysql> describe mytable;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| begin_date | datetime | YES | | NULL | |
| end_date | datetime | YES | | NULL | |
| status | varchar(200) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+