python写数据库校验_python_基础学习_04_mysql库验证与安装(mysql-python,mysql.connector)...

1、sudo apt-get install python-setuptools

2、sudo apt-get install libmysqld-dev

3、sudo apt-get install libmysqlclient-dev

4、sudo apt-get install python-dev

5、sudo easy_install mysql-python

测试下:

在python交互式窗口,import MySQLdb 试试,不报错的话,就证明安装好了。

预备

Python 2.7

Connector/Python 2.1.1

安装

1、下载源码包。

wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.1.tar.gz

2、解压缩。

tar -zxvf mysql-connector-python-2.1.1.tar.gz

3、安装。

python setup.py install

注:需要root权限

编程

#coding:utf8#使用 Connector/Python 进行查询操作。

importmysql.connector#创建连接

config ={'user':'uzone','password':'uzone','host':'127.0.0.1','port':19816,'database':'ucgc_sdk'}

conn= mysql.connector.connect(**config)#创建游标

cur =conn.cursor()#执行查询SQL

sql = "SELECT notice_id,notice_name,creator,ctime,modifier,mtime FROM notice"cur.execute(sql)#获取查询结果

result_set =cur.fetchall()ifresult_set:for row inresult_set:print "%d, %s, %s, %d, %s, %s" % (row[0],row[1],row[2],row[3],row[4],row[5])#关闭游标和连接

cur.close()

conn.close()

部分转载:http://aofengblog.blog.163.com/blog/static/6317021201522084715866/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值