http://nomadian.egloos.com/669706#!/bin/bash
# Created by : rootman
# Subject : Optimizing All of MySql DB tables
# --------------------------------------------------
#

DB_cnt=0;
DB_pass="xxxxxxxxxxxxx"
Total_Table=0;
DB_str=`mysql -u root -p${DB_pass} -e"show databases"`;
for DB_for in ${DB_str}
    do
        if [ ${DB_for} != "Database" ]; then
            TABLE_cnt=0;
            Table_str=`mysql -u root -p${DB_pass} -e"show tables" ${DB_for}`;
            for TABLE_for in ${Table_str}
            do
                Op_Str=`mysql -u root -p${DB_pass} -e"optimize table $TABLE_for" ${DB_for}`;
                echo " - DBName : ${DB_for} --> ${TABLE_for} optimized.";
                let TABLE_cnt=TABLE_cnt+1;
            done
            echo "------------------------> ${TABLE_cnt} Table of ${DB_for} DB Optimization Completed.";
            let Total_Table=Total_Table+${TABLE_cnt};
            sleep 1;
            let DB_cnt=DB_cnt+1;
        fi;
    done
echo "====================================================================================";
echo "- 호스트명 : `hostname` 에 대한 DB ${DB_cnt}개, 토탈테이블 ${Total_Table} 최적화 완료.";
echo "====================================================================================";

profile

이브리타, 나의 에뜨와르
너와 내가 공유하는 추억
너와 내가 만들 추억