ergodic_db_tb.py,,遍历数据库表及其相关表操
ergodic_db_tb.py,,遍历数据库表及其相关表操
遍历数据库表及其相关表操作
#!/usr/bin/pythonimport MySQLdbimport getoptimport sysfrom datetime import datetimeconf_host = '127.0.0.1'conf_port = 3306conf_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 + "';") 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()#该片段来自于http://byrx.net
相关内容
- 如何获得python对象变量的类型名字,python对象变量类型
- python从url中获取文件名,,import urlli
- 在Django中使用group_by,django使用group_by,在Django中怎样使
- python 显示错误的堆栈信息,python堆栈,python中有专门处
- 找零时纸币/硬币数量最少的算法,找零纸币硬币算法
- 计算未来某个时间点到现在还有多久,未来到现在,im
- python计算两个日期相差的天数,python天数,d1 = datetim
- python实现的端口转发器,python端口转发,由于工作需要用
- 求圆周率的代码,求拍。,求圆周率代码,import sysde
- python从list中删除元素,pythonlist元素,从python的list
评论关闭