输入banner图图片脚本导航/分类

python链接mysql

#!/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数据库