Get the App
SLTechnology News&Howtos  ›  Database  › 

Use python to operate mysql database (bulk insert data)

Shulou Source: shulou.com Published: 2022-06-01 21:36:57 10月03日 Update

#! / usr/bin/env python#-*-coding: utf-8-*-import MySQLdb# establish a connection conn = MySQLdb.connect (host='127.0.0.1',user='root',passwd='1qaz#EDC',db='test_db') cur = conn.cursor () # manipulate the data li = [('tanzhenx','shaoguan'), (' huangmengdie','shaoguan')] # define a list containing multiple tuples Cur.executemany ('insert into user (name,address) values (% s)', li) # bulk insert data conn.commit () # submit request in each tuple, otherwise the data will not be written to the database # close database connection cur.close () conn.close ()

Tags: Data database multiple utf-8 Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Shulou Tech Info Linux Apple