python怎么将列表保存到mysql

731
2020/12/3 17:27:31
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

python怎么将列表保存到mysql

python使用db实现将列表保存到mysql中 

具体方法如下:

import MySQLdb

db=MySQLdb.connect(passwd="moonpie",db="thangs")

c=db.cursor()

c.executemany(

      """INSERT INTO breakfast (name, spam, eggs, sausage, price)

      VALUES (%s, %s, %s, %s, %s)""",

      [

      ("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),

      ("Not So Much Spam Plate", 3, 2, 0, 3.95 ),

      ("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )

      ] )

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python如何绑定域名解析