首页 > 数据库技术 > 详细

python中操作mysql

时间:2017-10-04 14:53:14      阅读:217      评论:0      收藏:0      [点我收藏+]

0 安装模块

pip install MySQLdb  #安装MySQLdb模块

 

1 MySQLdb的使用

import MySQLdb

conn = MySQLdb.connect(host="",user=‘‘,passwd=‘‘,db=‘‘,charset=‘‘,port=3306)  #连接数据库

cursor = conn.cursor()


sql = create table ...  # 执行语句
cursor.execute(sql)

sql = insert into table values(%s)  #插入数据
data = male
cursor.execute(sql,data)

sql = select ...    #获取数据
cursor.execute(sql)
rows = cursor.fetchall()

cursor.close()    #关闭
conn.commit()
conn.close()

 

python中操作mysql

原文:http://www.cnblogs.com/liaohuiqiang/p/7625549.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!