shell脚本建多库、多表、多实例
cat createdbtable.sh #!/bin/bash #-------------------------------------------------- #Created:2015-05-26 #Author:jimmygong #Mail:[email protected] #Function: #Version:1.0 #-------------------------------------------------- mysqluser="mysql" mysqlpass="redhat" mysqlport="3306" alldatabases=(aaa bbb ccc ddd eee fff ggg hhh iii jjj) alltables=(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10) function mysqlconn () { mysqlip=$1 comm=$2 mysql -u${mysqluser} -p${mysqlpass} -h${mysqlip} -P${mysqlport} -e "$comm"|sed 1d } function createdbtable () { for ((j=0;j<${#alldatabases[*]};j++)) do ( mysqlconn $1 "CREATE DATABASE IF NOT EXISTS ${alldatabases[$j]}"; for ((k=0;k<${#alltables[*]};k++)) do mysqlconn $1 "use ${alldatabases[$j]};CREATE TABLE ${alltables[$k]} (id int not null,name char(20))"; done )& done wait } createdbtable "10.0.0.104" createdbtable "10.0.0.105" exit 0
本文出自 “7928217” 博客,请务必保留此出处http://7938217.blog.51cto.com/7928217/1655465
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。