# -*- coding: utf-8 -*-
# Filename mysqlInsertMany.py
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="run54543",
database="spring_db"
)
mycursor = mydb.cursor()
sql = "INSERT INTO sites (name, url) VALUES (%s, %s)"
val = [
('Google', 'https://www.google.com'),
('Github', 'https://www.github.com'),
('Taobao', 'https://www.taobao.com'),
('stackoverflow', 'https://www.stackoverflow.com/'),
('ruoo',None )
# 重点是这个None,注意没有''
]
mycursor.executemany(sql, val)
mydb.commit() # 数据表内容有更新,必须使用到该语句
print(mycursor.rowcount, "记录插入成功。")
————————————————
版权声明:本文为CSDN博主「春天的菠菜」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/legend818/article/details/90210034
网友评论