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

- Type: PHP
- Runs: On demand
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: database, mysql, innodb
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/perf-convert-myisam-to-innodb/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Convert MyISAM Database Tables to InnoDB" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
