Convert MyISAM Database Tables to InnoDB
Run on demand to convert your site's remaining MyISAM tables to InnoDB, the modern MySQL engine that handles many visitors at once far better and survives crashes more safely.
Opens WPIDE on
Code
global $wpdb;
$wpide_tables = $wpdb->get_col( $wpdb->prepare(
"SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s AND ENGINE = 'MyISAM' AND TABLE_NAME LIKE %s",
DB_NAME,
$wpdb->esc_like( $wpdb->prefix ) . '%'
) );
if ( ! $wpide_tables ) {
echo 'All tables already use InnoDB.';
} else {
foreach ( $wpide_tables as $wpide_table ) {
$wpide_ok = false !== $wpdb->query( 'ALTER TABLE `' . esc_sql( $wpide_table ) . '` ENGINE=InnoDB' );
printf( "%s: %s\n", esc_html( $wpide_table ), $wpide_ok ? 'converted' : 'failed (' . esc_html( $wpdb->last_error ) . ')' );
}
}
Notes
Back up the database first and run it during a quiet period, since large tables take a while; tables already using InnoDB are skipped.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.