Python——链接操做数据库

1.安装MySQL驱动程序。下载自动安装包,双击安装便可,很是简单。数据库

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

import MySQLdbconn=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()
相关文章
相关标签/搜索