#! /usr/bin/env bash# This is an example script that finds MyISAM tables in a database # and converts them InnoDB. It assumes the user has passwordless # access to the database.# Store the database namedb_name=testdb
# Store any MyISAM tables in an arrayreadarray -t myisam_tables < <(mysql --skip-column-names --batch --execute "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db_name' AND ENGINE = 'MyISAM'")# Check if the array contains items, and if so convert the tablesif["${#myisam_tables[@]}" -ge 1];thenfor table in "${myisam_tables[@]}";do mysql "$db_name" --execute "ALTER TABLE $table ENGINE = 'InnoDB'"doneelseecho"No MyISAM tables found in database $db_name"fi
Used in knowledgebase article about converting MyISAM tables to InnoDB.