프리이미지
사이트 내 전체검색

DB 테이블 optimize / aleter table 일괄 처리

페이지 정보

작성일14-10-15 04:11

본문

#!/bin/bash

 
if [ $# -lt 2 ]; then
        echo "You must specify database host"
        echo "Eg. script.sh MY_DATABSE 192.168.10.1"
        exit
fi
 
db="$1"
host="$2"
user="root"
 
stty -echo
read -p "Enter MySQL's Admin password: " password
stty echo
 
mysql -u $user --password=$password -h $host --batch --skip-column-names $db -e "SHOW TABLES" |
while read table; do
        echo $table &&
        time mysql -u $user --password=$password -h $host $db -e "ALTER TABLE $table ENGINE=INNODB"

done 

 

=====================================================

 

 

#!/bin/bash db="DB명" host="localhost" user="root" password="DB암호" mysql -u $user --password=$password -h $host --batch --skip-column-names $db -e "SHOW TABLES" | while read table; do echo ALTER TABLE $table ENGINE=INNODB && time mysql -u $user --password=$password -h $host $db -e "ALTER TABLE $table ENGINE=INNODB" done mysql -u $user --password=$password -h $host --batch --skip-column-names $db -e "SHOW TABLES" | while read table; do echo optimize TABLE $table && time mysql -u $user --password=$password -h $host $db -e "optimize TABLE $table" done

 

 

 

 

게시물 검색