shell批量增刪改查百庫百表(mysql)

來源:互聯網
上載者:User

標籤:shell

一、基礎環境1、版本cat /etc/debian_version 7.82、核心uname -r3.2.0-4-amd643、ip(eth0)10.1.10.11710.1.10.1854、2台機器上都設定許可權grant all privileges on `xxx%`.* to ‘jimmy‘@‘10.1.10.%‘ identified by ‘redhat‘;flush privileges;5、要注意資料庫必須監聽在相應本機IP地址上二、shell指令碼函數說明redirectlog           #記錄日誌createdb              #建立庫createtb              #建立表 三、具體代碼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 (){    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"$1"        let "dbfront+=1"    done}function createtbsql (){    cat <<EOF > $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"$1" "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 "+%s"` exit 0

本文出自 “7928217” 部落格,請務必保留此出處http://7938217.blog.51cto.com/7928217/1707546

shell批量增刪改查百庫百表(mysql)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.