參考博客:菜鳥(niǎo)的成長(zhǎng)的博客
python中空值為None丽蝎,而MySQL中的空值為NULL芒炼,在插入空值時(shí)可通過(guò)如下方法完成:
import pymysql
conn = pymysql.connect(host="localhost", user="root", passwd="12345", db="MyDB", charset="utf-8")
cur = conn.cursor()
cur.execute("**insert into** My_table(attr1, attr2, attr3) **values** (%s, %s, %s)",
(entry_1 **or** "NULL" , entry_2 **or** "NULL", entry_3 **or** "NULL"))
cur.close()
conn.commit()
conn.close()