Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2141917
  • 博文数量: 103
  • 博客积分: 206
  • 博客等级: 入伍新兵
  • 技术积分: 1819
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-12 10:24
个人简介

效字当先,以质为本。

文章分类
文章存档

2019年(2)

2018年(4)

2017年(7)

2016年(3)

2015年(14)

2014年(33)

2013年(31)

2012年(9)

分类: Python/Ruby

2015-02-26 15:51:44

1、连接oracle数据库:

点击(此处)折叠或打开

  1. #encoding:utf-8
  2. from sqlalchemy.ext.sqlsoup import SqlSoup
  3. from sqlalchemy import create_engine
  4. """连接数据库"""
  5. db_data = create_engine('oracle://username:password@xxx.xxx.xxx.xxx:1521/logpub',pool_recycle=60)
  6. db = SqlSoup(db_data)

  7. """查询数据"""
  8. sql = "select t.user_name,t.channel_name,t.channel_id,t.local_path from PUB_URL t where t.content_date = to_date('2015-02-26','yyyy-mm-dd') and t.local_path like '%%/data/Data%%'"
  9. channels_massage = db.connection().execute(sql).fetchall()
  10. db.session.close()
2、连接mysql数据库:

点击(此处)折叠或打开

  1. import MySQLdb

  2. conn_athena = MySQLdb.connect(host="192.168.xx.xx",user='xxx',passwd='xxxx',db='xxx')
  3. cursor_athena = conn_athena.cursor()
  4. sql = "update hadoop_jobs t set t.status = 0"
  5. cursor_athena.execute(sql)
  6. cursor_athena.commit()
  7. cursor_athena.close()
  8. conn_athena.close()
3、连接redis数据库:

点击(此处)折叠或打开

  1. import redis

  2. r = redis.Redis(host=ip, port=port, password=pwd, db=db)
  3. keys = r.keys()
  4. print keys
仅用于个人总结,仅供参考!

阅读(2041) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~