3

I converted all my tables to InnoDB, but the MySQL server (which I can't access, as I'm on shared hosting) has MyISAM as the default, so every new table that Wordpress creates (e.g. when I add a new site on my multisite) uses the MyISAM engine and I have to alter it manually. Can I somehow set Wordpress up to enforce the InnoDB engine when creating new tables?

I know that by default Wordpress doesn't specify anything and lets the table use the default engine, but I'm wondering if there is some plugin where I could add the

ENGINE=InnoDB

clause to all the CREATE TABLE queries.

3

If the code creating new tables uses dbDelta() (it should), you can filter the query (see wp-admin/includes/upgrade.php):

add_filter( 'dbdelta_create_queries', function( Array $queries )
{
    foreach ( $queries as $table => $query )
    {
        if ( FALSE !== stripos( $query, 'CREATE TABLE' ) )
        {
            // change the query here
        }
    }

    return $queries;
});
  • Thanks for the pointer! Found the code in question. Maybe it could be made even simpler by adding a filter for 'dbdelta_create_queries', as I see it's already defined in the code to match "|CREATE TABLE ([^ ]*)|". – metakermit Sep 1 '13 at 15:45
  • @kermit666 Indeed, that’s better. :) Made an update to my answer. – fuxia Sep 1 '13 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.