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
时间: 2024-09-27 17:04:15