python自动导出数据脚本_用python生成一个导出数据库的bat脚本文件

# 环境: python3.x

def getExportDbSql(db, index): # 获取导出一个数据库实例的sql语句

sql = 'mysqldump -u%s -p%s -h%s -P%d --default-character-set=utf8 --databases mu_ins_s%s > %s.s%d.mu_ins_%d.sql' %(db['user'], db['pwd'], db['host'], db['port'], index, db['server'], index, index)

return sql

def createDbBackupFile(fname, dbList): # 生成数据库导出的语句保存到文件

if not fname or not dbList:

return False

f = open(fname, 'w')

if f:

f.write('echo @off\n\n')

for db in dbList:

for index in db['indexList']:

f.write('REM %s.s%d\n' %(db['server'], index))

f.write('%s\n\n' %getExportDbSql(db, index))

f.write('\n')

f.close()

return True

return False

def initDb(user, pwd, host, port, server_name, indexList): # 生成db字典对象并返回

db = {}

db['user'] = user

db['pwd'] = pwd

db['host'] = host

db['port'] = port

db['server'] = server_name

db['indexList'] = indexList

return db

def displayDb(db):

print('user =', db['user'])

print('pwd =', db['pwd'])

print('host =', db['host'])

print('port =', db['port'])

print('server =', db['server'])

print('indexList =', db['indexList'])

print('\n')

def displayList(list):

for item in list:

displayDb(item)

if __name__ == '__main__':

db1 = initDb('root', '', '127.0.0.1', 3306, 'th1', [10000, 1, 3])

db2 = initDb('root', '', '127.0.0.1', 3306, 'th2', [10000, 1])

dbList = []

dbList.append(db1)

dbList.append(db2)

#displayList(dbList)

createDbBackupFile('export00.bat', dbList)

# 何问起 hovertree.com

Python生成PASCAL VOC格式的xml标注文件

Python生成PASCAL VOC格式的xml标注文件 PASCAL VOC数据集的标注文件是xml格式的.对于py-faster-rcnn,通常以下示例的字段是合适的:

C#对bat脚本文件的操作示例

实现C#操作bat脚本文件 using System;using System.Collections.Generic;using System.ComponentModel;using System ...

用 Python 写一个 NoSQL 数据库Python

NoSQL 这个词在近些年正变得随处可见. 但是到底 “NoSQL” 指的是什么? 它是如何并且为什么这么有用? 在本文, 我们将会通过纯 Python (我比较喜欢叫它, “轻结构化的伪代码”) 写 ...

用Python写一个向数据库填充数据的小工具

一. 背景 公司又要做一个新项目,是一个合作型项目,我们公司出web展示服务,合作伙伴线下提供展示数据. 而且本次项目是数据统计展示为主要功能,并没有研发对应的数据接入接口,所有展示数据源均来自数据库 ...

Python生成一个不含回文字符串的字符串

[本文出自天外归云的博客园] 回文字符串介绍 回文字符串就是对称的字符串,例如: “ABA” “ABBA” “ABCBA” 题目 给定一个字符串,请发明一种方法,让字符串中不包含回文字符串. 我的解法 ...

用 python 生成一个简单的词云图

import jieba from nltk import * from wordcloud import WordCloud import matplotlib.pyplot as plt word ...

Python 生产环境MySQL数据库增量备份脚本

MySQL数据库常用的办法是通过MySQLdump导出sql进行备份,但是不适合数据量很大的数据库,速度,锁表是两个严重的问题.前面写了一遍文章介绍xtrabackup的热备工具,见 http://w ...

python 检索一个目录下所有的txt文件,并把文件改为.log

检索一个目录及子目录下所有的txt文件,并把txt文件后缀改为log: import os f_path = r'C:\Users\PycharmProjects\mystudy\Testfolder ...

python 写一个类似于top的监控脚本

最近老板给提出一个需要,项目需求大致如下:      1.用树莓派作为网关,底层接多个ZigBee传感节点,网关把ZigBee传感节点采集到的信息通过串口接收汇总,并且发送给上层的HTTP Serve ...

随机推荐

【JAVA - SSM】之MyBatis与原生JDBC、Hibernate访问数据库的比较

首先来看一下原生JDBC访问数据库的代码: public static void main(String[] args) { // 数据库连接 Connection connection = null ...

[C# 基础知识系列]专题一:深入解析委托——C#中为什么要引入委托

转自http://www.cnblogs.com/zhili/archive/2012/10/22/Delegate.html 引言: 对于一些刚接触C# 不久的朋友可能会对C#中一些基本特性理解的不 ...

php.ini与php-fpm.conf配置文件的区别

php-fpm.conf是PHP-FPM特有的配置文件 php.ini是所以php模式中必须的配置文件 两者的区别是,php-fpm.conf是PHP-FPM进程管理器的配置文件,php.ini是PH ...

python _winreg模块

详细资料请参考:https://docs.python.org/2/library/_winreg.html 一.常用函数功能介绍 OpenKey() - 打开一个key ############## ...

eclipse使用异常An error has occurred.see error log for more details eclipse

eclipse使用异常An error has occurred.see error log for more details eclipse 解决Eclipse,MyEclipse出现An erro ...

JAVA 没有重载运算符,那么 String 类型的加法是怎么实现的,以及String类型不可变的原因和好处

1, JAVA 不具备 C++ 和 C# 一样的重载运算符 来实现类与类之间相互计算 的功能    这其实一定程度上让编程失去了代码的灵活性, 但是个人认为,这在一定程度上减少了代码异常的概率     ...

spring IOC简单分析

Spring IOC 体系结构 BeanFactory(BeanFactory 里只对 IOC 容器的基本行为作了定义,根本不关心你的 bean 是如何定义怎样加载的.正如我们只关心工厂里得到什么的产 ...

php请求php

function post2($url, $data){//file_get_content $postdata = http_build_query( $data ); $opts = array( ...

JDBC连接MySql,配置url报错

使用JDBC连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one ...

JQuery 对表格的详细操作