python 操作 MySql 数据库

来源:互联网 发布:淘宝小号在哪里购买 编辑:程序博客网 时间:2024/05/01 08:09

1、安装Python的MySQL编程库(win7 64位)

下载 MySQL-python-1.2.3.win-amd64-py2.7.exe  ,运行安装。


2、MySQL的Python代码实例

import MySQLdb
try:
    conn=MySQLdb.connect(host='912.168.0.1',user='user',passwd='password',db='tablename',port=3306)

    cur=conn.cursor()
    cur.execute('select * from device limit 10')
    cur.close()
    conn.close()
except MySQLdb.Error,e:
    print "Mysql Error %d: %s" % (e.args[0], e.args[1])

更多 http://www.cnblogs.com/rollenholt/archive/2012/05/29/2524327.html


0 0
原创粉丝点击