I. Basic Environment 1, version cat /etc/debian_version 7.82, kernel uname -r3.2.0-4-amd643, IP (eth0) 10.1.10.11710.1.10.1854 , 2 machines are set permissions grant all privileges on ' xxx% ' .* to ' Jimmy ' @ ' 10.1.10.% ' identified by ' Redhat '; flush privileges;5, be aware that the database must be listening on the corresponding native IP address two, shell script function Description redirectlog #记录日志createdb #创建库createtb #创建表 Third, specific code cat createdbtb.sh #!/bin/bash#------------------ --------------------------------#Author: jimmygong#email:[email protected] #FileName: createdbtb.sh#function : #Version: 1.0#created:2015-10-29#--------------------------------------------------currdate=$ (date +%y%m% d) dbuser= "Jimmy" dbpass= "Redhat" logdir= "/root/log" tmptb= "Table.sql" tmpdb= "Db.sql" Function redirectlog () {&NBSP;&NBSP;&NBSP;&Nbsp;logfile= $logdir/${currdate}log mkdir -p $logdir exec 1> $logfile exec 2> $logfile}function createdbsql () { cat <<EOF > $tmpdb create database $1EOF}function createdb () { dbfront=0 dbend=100 while [[ $dbfront -lt $dbend ]] do dbx= ' printf "%02d" $dbfront createdbsql xxx$dbx cat $ Tmpdb|mysql -u "$dbuser" -p "$dbpass" -h "$" let "Dbfront+=1" done}function createtbsql () { cat <<eof >&nbSP; $TMPTB create table if not exists t_xxx_$1 ( userid INT UNSIGNED NOT NULL DEFAULT ' 0 ', toolid int unsigned not null default ' 0 ', number int UNSIGNED NOT NULL DEFAULT ' 0 ', get_time int unsigned not null default ' 0 ', primary key (userid, ToolID) ) ENGINE=innodb, CHARSET=utf8; eof}function createtb () { dbfront=0 dbend=100 tablefront=0 tableend=100 while [[ $dbfront -lt $dbend ]] do dbx= ' printf "%02d" $dbfront ' echo $dbx while [[ $ tablefront -lt $tableend ]] do tbx= ' printf "%02d" $tablefront createtbsql $TBX cat $TMPTB |mysql -u "$dbuser" -p "$dbpass" - H "$" "xxx$dbx" let " Tablefront+=1 " done let "Dbfront+=1" let "tablefront=0" done}redirectlogcreatedb 10.1.10.185createtb 10.1.10.185createdb 10.1.10.117createtb 10.1.10.117end= ' DATE&NBSP; " +%s "' exit 0
This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1707546
Shell batch additions and deletions to the Hundred Library Hundred Table (MySQL)