当前位置:Gxlcms > 数据库问题 > python链接mysql

python链接mysql

时间:2021-07-01 10:21:17 帮助过:27人阅读

#!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 import MySQLdb 4 # 打开数据库连接 5 db = MySQLdb.connect(host=127.0.0.1, port=3306, user=root, passwd=‘‘, db=xxx, charset=utf8) 6 # 使用cursor()方法获取操作游标 7 cursor = db.cursor() 8 # 使用execute方法执行SQL语句 9 cursor.execute("SELECT VERSION()") 10 data = cursor.fetchone() 11 print "mysql版本%s" %data 12 # 关闭数据库连接 13 db.close()

这是最基本的一个小例子

 

python链接mysql

标签:cursor   etc   xxx   int   http   user   pytho   下载   mysql数据库   

人气教程排行