玩蛇网提供最新Python编程技术信息以及Python资源下载!
python零基础培训

python遍历数据库表及其相关表操作

python 培训

python遍历数据库表及其相关表操作.

相关文章推荐:
Python 并行遍历zip()函数使用方法
Python遍历文件夹目录与文件操作

#!/usr/bin/python

import MySQLdb
import getopt
import sys
from datetime import datetime

conf_host = '127.0.0.1'
conf_port = 3306
conf_user = 'root'
conf_pass = ''
conf_db = 'information_schema'
conf_bind_db = 'mydns'

def main():

    db_bind = MySQLdb.connect(host = conf_host, port = conf_port, user = conf_user, passwd = conf_pass, db = conf_bind_db)
    cursor_bind = db_bind.cursor()
    db = MySQLdb.connect(host = conf_host, port = conf_port, user = conf_user, passwd = conf_pass, db = conf_db)
    cursor = db.cursor()
    file = open("output.txt","w")
    cursor.execute("select table_name from tables where table_name regexp'rg_' and table_schema ='" + conf_bind_db + "';")
    #www.iplaypython.com

    for row in cursor.fetchall():
        print row[0]
        sql = "select zone,host,type,data,ttl from  " + row[0] + " where zone regexp'(cnc|ct|edu|ov).centos.com' and data='originboss.centos.com.' and type='cname';"
        cursor_bind.execute(sql)
        result = cursor_bind.fetchall()
        for row in result:
	            print row[0],row[1],row[2],row[3],row[4]        
    cursor.close()
    db.close()    
    
    cursor_bind.close()
    db_bind.close()
    
if __name__ == '__main__':
    main()

站长推荐阅读相关内容:
linux基础入门教程

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypython.com/code/base/b2471.html [复制]



微信扫描下图可直接关注Python公众号

玩蛇网Python QQ群,欢迎加入: ① 279974227 玩蛇网Python新手群
修订日期:2016年04月07日 - 15时04分41秒 发布自玩蛇网

我要分享到:
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
相关文章推荐
别人正在看
特别推荐
站长推荐:
去顶部去底部