これはマルチスレッドを使用したいbashスクリプトコードの一部です。
for DATABASE in $DATABASES ; do
echo Converting $DATABASE
# Check if the table is MyISAM (we don't want to convert InnoDB tables over and over again)
TABLES=$(echo "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA = '$DATABASE' and ENGINE = 'MyISAM'" | $MYSQL_COMMAND)
for TABLE in $TABLES ; do
echo Converting MyISAM $TABLE to InnoDB
echo "ALTER TABLE $TABLE ENGINE = INNODB" | $MYSQL_COMMAND $DATABASE
done
if [ "x$TABLES" = "x" ] ; then
echo No MyISAM tables found in $DATABASE database
fi
echo
done
FOR
マルチスレッドを使用できますか?
スクリプトを書き直してなどでやろうと思いますがxargs -P3 -n1 -I{}
そうです。汚い大きな本。
答え1
私がやった!
function convert_db() {
echo Converting $1
# Check if the table is MyISAM (we don't want to convert InnoDB tables over and over again)
TABLES=$(echo "SELECT TABLE_NAME FROM information_schema.TABLES where TABLE_SCHEMA = '$1' and ENGINE = 'MyISAM'" | $MYSQL_COMMAND)
for TABLE in $TABLES ; do
echo Converting MyISAM $TABLE to InnoDB
echo "ALTER TABLE $TABLE ENGINE = INNODB" | $MYSQL_COMMAND $1
done
if [ "x$TABLES" = "x" ] ; then
echo No MyISAM tables found in $1 database
fi
echo
}
for DATABASE in $DATABASES ; do
convert_db $DATABASE &
done