导入MysqL驱动:
import MysqL.connector
conn = MysqL.connector.connect(user='root',password='000000',database='test')
cursor = conn.cursor()
cursor.execute('create table user (id varchar(20) primary key, name varchar(20))') # 创建user表
cursor.execute('insert into user (id, name) values (%s, %s)', ['1', 'Michael']) # 插入一行记录,注意MysqL的占位符是%s:
cursor.rowcount # 显示插入的数据量
conn.commit() # 提交事务
cursor.close() # 关闭Cursor
# 提交事务# 提交事务# 提交事务 TRANSLATE with x English TRANSLATE with copY THE URL BELOW Back EMbed THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back