Convert MyISAM Tables to InnoDB
Steps
Convert the MyISAM tables a database inherited from an old MySQL installation may still hold to InnoDB, the transactional storage engine MySQL Storage Engine and Character Set shows XWiki requires.
- Stop XWiki, then back up the database with the database backup commands: changing a table's engine rewrites it and cannot be undone.
- List the engine of every table, replacing xwiki with your database name if it differs:
SELECT table_name, engine FROM information_schema.tables WHERE table_schema = 'xwiki';Every table reporting MyISAM has to be converted. If none does, there is nothing to do here.
- Save this script and run it as the MySQL root user:
#!/bin/bash MYSQL_COMMAND=mysql TO_ENGINE=INNODB DATABASES=$(mysql -N -s -r -e 'show databases'|grep -v ^information_schema$|grep -v ^mysql$) for db in $DATABASES do echo "Working on database $db..." echo "" TABLES=$(mysql -N -s -r -e "show tables from $db;") for tb in $TABLES do $MYSQL_COMMAND -e "ALTER TABLE $db.$tb ENGINE = $TO_ENGINE;" done $MYSQL_COMMAND -e "SELECT table_name,Engine,table_collation FROM information_schema.tables WHERE table_schema = '$db';" echo "" echo "" doneIt walks every database of the server except information_schema and mysql, converts each of their tables to InnoDB, and prints the engine and collation of the tables it produced. On a server that also hosts databases other than the wiki's, narrow the DATABASES line to the wiki's own databases before running it. If the MySQL user needs credentials, add -u root -p to each mysql call.
- Start XWiki.
- Confirm that no table was left on the old engine. Asking for the tables that are not on InnoDB turns the script's closing query into a single check:
SELECT table_name, engine, table_collation FROM information_schema.tables WHERE table_schema = 'xwiki' AND engine <> 'InnoDB';An empty result is the confirmation: every table of the database is on InnoDB, so a save that fails halfway through is rolled back instead of leaving the wiki inconsistent.