Mysql.py 699 Bytes
import pymysql

'''
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd ='', db='')
cur = conn.cursor()
cur.execute("SELECT * FROM wenzhoubank.personal")
for r in cur.fetchall():
    print(r)

#cur.close()
conn.close()
'''

db = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='')

# 使用cursor()方法获取操作游标
cursor = db.cursor()

sql = """INSERT INTO personal(reportseq,
         querytime, name)
         VALUES (0001, '2017/7/19', 'Laji')"""

try:
   # 执行sql语句
   cursor.execute(sql)
   # 提交到数据库执行
   db.commit()
except:
   # Rollback in case there is any error
   db.rollback()

# 关闭数据库连接
db.close()