/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
小编好不容易为搞编程的朋友们弄来了这款MySQL Connector Python,它可是MySQL官方提供的Python连接MySQL数据库的驱动程序。并且MySQL Connector Python还可处理大的数据包,支持连接压缩协议和SSL等。看小编如此辛苦的份上有需要的就赶快拿走使用吧。
1到Python.org上查找所用的包,
2代码编写,import mysql.connector:
a连接数据库: conn = mysql.connector.connect(host='localhost', user='root',passwd='pwd',db='test')
b获取操作句柄:cursor = conn.cursor()
c执行sql:cursor.execute(sql)、cursor.executemany(sql, val)
d获取查询结果:alldata = cursor.fetchall()
e关闭连接:cursor.close()、conn.close()