Skip to content
Justin SilverTECHNOLOGY, TRAVEL & EVERYTHING IN BETWEEN

Technology

Convert From MyISAM to InnoDB Engine

April 22, 2014

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"