Python——连接操作数据库

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()

猜你喜欢

转载自www.cnblogs.com/wanglei-xiaoshitou1/p/9429888.html