更改mysql表引擎(shell)

來源:互聯網
上載者:User

標籤:shell myisam innodb

一、基礎環境1、版本cat /etc/redhat-release CentOS release 6.6 (Final)2、核心uname -r2.6.32-504.el6.x86_643、ip(eth0)10.1.10.23二、shell指令碼函數說明redirectlog           #記錄日誌用的checkengine           #檢查innodb是否支援及查看預設引擎generatedb            #匯出需要的DB庫generatetable         #匯出需要更改引擎表到某個檔案alterengine           #將某個檔案中的表進行引擎更改三、cat myisamtoinnodb.sh#!/bin/bash#--------------------------------------------------#Author:jimmygong#Email:[email protected]#FileName:myisamtoinnodb.sh#Function: #Version:1.0 #Created:2015-08-07#--------------------------------------------------currdate=$(date +%Y%m%d)dates=`date "+%s"`sleeptime=2dbuser="test"dbpass="123456"dbport="3306"dbip=$(ifconfig eth0|awk ‘/inet addr:/‘|awk -F: ‘{print $2}‘|awk -F" " ‘{print $1}‘)logdir="/opt/myisamtoinnodb"exclude="mysql information_schema"function mysqlcmd (){    comm=$1    mysql -u"$dbuser" -p"$dbpass" -h"$dbip" -P"$dbport" -sNe "$comm"}function redirectlog (){    logfile=$logdir/${currdate}_${dbip}_log    mkdir -p $logdir    exec 1>$logfile    exec 2>$logfile}function checkengine (){    defaultengine=`mysqlcmd ‘show engines‘|grep -i default|awk ‘{print $1,$2}‘`    echo "$defaultengine"    innodb=`mysqlcmd ‘show engines‘|grep -i innodb|grep -i yes`    if [[ ! -z "$innodb" ]]    then        echo "innodb enabled"    fi}function generatedb (){    i=0    dblist=`mysqlcmd ‘show databases‘`    for db in $dblist    do        rv=`echo $exclude|grep -w -i $db`        if [[ -n "$rv" ]]        then            continue;        fi        dbname[i]=$db        let i++    done}function generatetable (){    i=0    for db in ${dbname[@]}do    alltable=`mysqlcmd "use $db;show tables"|wc -l`    for ((j=1;j<=$alltable;j++))    do        table=`mysqlcmd "use $db;show tables;"|sed -n $j"p"`        for tablename in $table        do            engine=`mysqlcmd "use $db;show create table $tablename;"|grep -w -i "engine=myisam"`            if [[ $? = 0 ]]            then                echo $db $table >> $logdir/table.$dates            fi        done    donedone}function alterengine (){    [[ ! -e $logdir/table.$dates ]] && exit 1    while read db table     do        mysqlcmd "alter table $db.$table engine=innodb;"        sleep $sleeptime        echo $db $table $(date +%F:%T)    done < $logdir/table.$dates}redirectlogcheckenginegeneratedbgeneratetablealterengineexit 0


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

更改mysql表引擎(shell)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.