0

This question already has an answer here:

This is part of a bash script code I wish to use multi-threading

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

Is it possible for FOR to use multi-threading?

I was thinking about rewriting the script and doing it with xargs -P3 -n1 -I{} and so on, but it looks dirty to me.

marked as duplicate by Luka, Community Apr 18 '18 at 15:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

I did it!

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.