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

该博客展示了如何使用Python连接MySQL数据库,遍历特定模式的表,并执行相关查询操作。通过正则表达式筛选出包含特定字符串的table_name,并针对每个匹配的表查询特定数据条件,例如zone、host、type、data和ttl。
摘要由CSDN通过智能技术生成

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 + "

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值