ITeye博客

【转载】Python连接MySQL数据库

bzu334fc · 2012-01-19 09:47 · 技术杂绘 · 非技术 · Markdown

【转载】Python连接MySQL数据库 2011年08月07日   原文地址:Python连接MySQL数据库   文章来自:python - 搜搜关键词订阅            Python连接MySQL数据库    (2011-08-06 18:04:45)     1.连接的关键是安装MySQLdb模块(下载地址:  http://www.codegood.com/archives/4),我用的Python版本是2.7.2,要下载与Python相对应的版本.         2.下载好后安装,它会自动检测到计算机Python的安装路径,并自动填写模块解压路径(我的是:D:\Python27\Lib\site-packages\)。2.7版本的就是好,再也不用修改MySQLdb模块下的文件了。       3.编写conmysql.py:       def getmysqlinfo():      import MySQLdb      conn = MySQLdb.connect(host="localhost",               user="root",               passwd="wangxing",               db="test")      cursor = conn.cursor()      cursor.execute("select * from age")      res = cursor.fetchall()      print res      cursor.close()      conn.close()         4.Python (command line)下运行测试:                 前一篇: Python 遍历目录 获得文件属性
  原文地址:Python连接MySQL数据库   文章来自:python - 搜搜关键词订阅

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。