Convert MyISAM Tables to InnoDB

Last modified by Eleni Cojocariu on 2026/09/10 20:35

Steps

A database inherited from an old MySQL installation may still hold MyISAM tables. This converts them to InnoDB, the transactional storage engine XWiki requires, MySQL Storage Engine and Character Set explains what breaks without it.

  1. Stop XWiki, then back up the database with the database backup commands: changing a table's engine rewrites it and cannot be undone.
  2. 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.

  3. 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 ""
    
    done

    It 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.

  4. Start XWiki.
  5. 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.

Related

Get Connected