Shell进行MySQL表跨服务器传输小脚本
来源:互联网 发布:ps基线已优化 编辑:程序博客网 时间:2024/06/05 04:57
因开发与测试需要,经常需要临时性地将若干MySQL表跨服务器传输,于是通过Shell脚本封装命令行的“mysqldump”(dump操作)与mysql(import操作),就可以简单实现需求了。
#! /bin/bash# Author : 蛙鳜鸡鹳狸猿# create_ts :# program : do a MySQL table dump# crontab : NULL### __init__host_src=yourht_A # source db server config listuser_src=rootpswd_src=123dbas_src=yourdb_A#host_tar=yourht_B # target db server config listuser_tar=rootpswd_tar=456dbas_tar=yourdb_B#tble_dump=(tb_a tb_b tb_c) # dump table configcach_dump=/ # cache directory config### dump tablesfor tba in ${tble_dump[*]} do if mysqldump -h${host_src} -u${user_src} -p${pswd_src} --single-transaction --skip-lock-tables --set-gtid-purged=OFF ${dbas_src} ${tba} > ${cach_dump}${tba}.sql && \ mysql -h${host_tar} -u${user_tar} -p${pswd_tar} ${dbas_tar} < ${cach_dump}${tba}.sql && \ echo -e "\n\n ……${tba} dump OK…… \n\n" then > /dev/null else exit && echo -e "\n\n ……MySQL dump from ${dbas_src} to ${dbas_tar} failed…… \n\n" fi done## # clear cacheif cd ${cach_dump} && ls | grep .sql | xargs rm -f then echo -e "\n\n ……\(^o^)/YES ╮(╯▽╰)╭ \(^o^)/YES…… \n\n"else exit && echo -e "\n\n ……o(>﹏<)o YaMieDie o(>﹏<)o…… \n\n"fi# #
如以上小脚本所示,不同的操作只需要改动一下“__init__”部分的配置。另外,可能需要MySQL策略性的整库备份,参考:http://blog.csdn.net/sweeper_freedoman/article/details/52717911。
0 0
- Shell进行MySQL表跨服务器传输小脚本
- Shell进行MySQL表跨服务器增量更新同步小脚本
- 进行web服务器nginx的小脚本
- 一个shell小脚本
- Shell小脚本示例
- shell小脚本
- shell小脚本
- shell 小脚本
- 初试shell小脚本
- mysql 导出前缀相同表小脚本
- Shell实现MySQL定期备份策略小脚本
- 实现几个shell小脚本
- Linux 常用shell小脚本
- 查看Linux服务器网卡流量小脚本shell和Python各一例
- 一个shell防火墙的小脚本
- Shell下FTP获取文件小脚本
- 简单实用的shell小脚本
- Shell 小脚本集合----持续更新
- mysql命令查找数据库的data物理路径
- 安装employees
- Java线程池ThreadPoolExecutor源码分析
- NYOJ 220 推桌子(贪心)
- 编程术语及概念(Leading Dimension、哨兵)
- Shell进行MySQL表跨服务器传输小脚本
- Servlet理解与入门
- Add Digits
- Angular2-http
- 【Java并发】JAVA并发编程实战-读书笔记15
- cocos2dx 18个易忽略的知识点
- 枚举,typedef定义和使用
- Spring-理解依赖注入
- 说好了的闹钟