Convert From MyISAM to InnoDB Engine

If you ever have the need to convert a MySQL (or MariaDB) table from the MyISAM engine to the InnoDB engine, you can use the following script to get it done for an entire database. There are some caveats of course – InnoDB requires a primary key, does not support fulltext indexes, etc. – but if you’re feeling lazy….

DBUSER=root
DBPWD="my password";
DBNAME="database_name";
mysql -u "$DBUSER" -p"$DBPWD" "$DBNAME" -e \
"SHOW TABLE STATUS WHERE Engine='MyISAM';" | \
awk 'NR>1 {print "ALTER TABLE "$1" ENGINE = InnoDB;"}' | \
mysql -u "$DBUSER" -p"$DBPWD" "$DBNAME"

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *