您的位置:首页 > 博客中心 > 数据库 >

Python 学习之—连接mysql

时间:2022-03-14 02:19

下面我们使用MySQLdb 实现连接mysql 数据库并进行操作. 

#!/usr/bin/env python
# -*-coding:UTF-8-*-
import  MySQLdb
def connetMysql():
conn=MySQLdb.connect(user="admin",passwd="123456",host="XXX",db="test")
cursor = conn.cursor()
cursor.execute("select * from test;")
print "rows:cursor.rowcount() 
for row in cursor.fetchall():
print "note : ", row[0], row[1]
cursor.close() 
if __==‘__main__‘:
connectMysql()

更多资料关注:www.kootest.com ;技术交流群:182526995

热门排行

今日推荐

热门手游