import mysql.connector

cnx = mysql.connector.connect(user='xx',password='xx++.',host='139.107.11.166',database='sys')

#create users
cursor = cnx.cursor() cursor.execute('create table userr (id varchar(20) primary key,name varchar(20))') # insert sql data
cursor.execute('insert into userr (id,name) values (%s,%s)',['1','mmssd']) cursor.rowcount #commit transaction
cnx.commit()
cursor.close()

PYTHON MYSQL 的表创建和插入-LMLPHP

05-11 14:07