码迷,mamicode.com
首页 > 数据库 > 详细

Python连接mysql

时间:2016-06-11 14:27:12      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

下载MySQLdb:http://www.codegood.com/downloads

技术分享

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import MySQLdb
#打开数据库连接
con = MySQLdb.connect(‘localhost‘, ‘root‘, ‘123456‘,‘test‘)
#使用cursor()方法获取操作符
cursor = con.cursor()
#使用execute方法执行sql语句
cursor.execute(‘select version()‘)
#使用fetchone()方法获取一条记录
data = cursor.fetchone()

print ‘Database version :%s‘%data
#关闭数据库连接
con.close()

Python连接mysql

标签:

原文地址:http://www.cnblogs.com/2star/p/5575201.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!