PHP中高级工程师面试重点讲解视频课程
Go快速入门浅显易懂视频教程-基础篇
Go快速入门浅显易懂视频教程-中级篇
python操作mysql
阅读:383 分享次数:0

# 8.py
#code=utf-8
# python操作mysql

#导入驱动
import mysql.connector

# 连接mysql
conn = mysql.connector.connect(user='root', password='root', database='test', use_unicode=True)
cursor = conn.cursor()

# 创建user表
cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')

# 插入一行数据
cursor.execute('insert into user(id, name) values (%s, %s)', ['1', 'mack'])
print cursor.rowcount

# 提交事务
conn.commit()

# 执行查询
cursor = conn.cursor()
cursor.execute('select * from user where id = %s', ('1',))
values = cursor.fetchall()
print values




'''
执行结果
1
[(u'1', u'mack')]
'''

感觉本站内容不错,读后有收获?