码迷,mamicode.com
首页 > 数据库 > 详细

Python——连接操作数据库

时间:2018-08-06 14:38:15      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:pre   驱动程序   www   print   fetchone   int   serve   双击   mys   

1.安装MySQL驱动程序。下载自动安装包,双击安装即可,非常简单。

2.连接MySQL,下面是Python示例代码。




import MySQLdb
conn=MySQLdb.connect(host=‘localhost‘,
user=‘root‘,
passwd=‘自己密码‘,
db=‘数据库名称‘)
cursor = conn.cursor()
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
print "server version:", row[0]
cursor.close()
conn.close()

Python——连接操作数据库

标签:pre   驱动程序   www   print   fetchone   int   serve   双击   mys   

原文地址:https://www.cnblogs.com/wanglei-xiaoshitou1/p/9429888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!