Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

WordPress - Convert MyISAM To InnoDB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EasyEngine

Home Tutorials Mysql Convert MyISAM to InnoDB

Convert MyISAM to InnoDB


Recently we migrated all MyISAM tables to InnoDB for most of our sites.
We saw some improvement in mysql performance, specially when editing posts. I think earlier parallel write on

wp_posts

table were

getting blocked because MyISAM do not support row-level locking. There might be more logic to it but I am no database expert to
comment on it.
Anyway, below is how we moved our WordPress sites. You may nd process useful.
Important: Backup rst, proceed later!

Backing up a table in SQL


I know I remind you to backup. Just in case you missed it, below is a quick way to backup a table MySQL itself. This may come handy if you
are playing on live site.
Run following twocommandsto backup

wp_posts

CREATETABLEwp_posts_BAKLIKEwp_posts;
INSERTwp_posts_BAKSELECT*FROMwp_posts;

CREATETABLEwp_postmeta_BAKLIKEwp_postmeta;
INSERTwp_postmeta_BAKSELECT*FROMwp_postmeta;

and

wp_postmeta

tables.

Drop Fulltext Indexes


If you are using a plugin like YARPP, you need to drop fulltext indexes.If you proceed without dropping fulltext indexes, you will get an
error going ahead.
Below are commands to drop YARPPs fulltext indexes.
ALTERTABLEwp_postsDROPINDEXyarpp_title;
ALTERTABLEwp_postsDROPINDEXyarpp_content;

For all tables in ONE database


Below is a query to help you nd all fulltext indexes on all your mysql tables for database

db_wordpress.

mysqle"SELECTconcat('ALTERTABLE',TABLE_NAME,'DROPINDEX',index_name,';')
FROMinformation_Schema.STATISTICS
WHEREtable_schema='db_wordpress'
ANDindex_type='FULLTEXT'ORDERBYindex_name"|tailn+2>drop.sql

For all tables in ALL databases


Alternatively, if you wish to drop indexes for all tables from all databases (except mysql database itself), you can use following query:
mysqle"SELECTconcat('ALTERTABLE\`',TABLE_SCHEMA,'\`.',TABLE_NAME,'DROPINDEX',index_name,';')
FROMinformation_Schema.STATISTICS
WHERETABLE_SCHEMA!='mysql'
ANDindex_type='FULLTEXT'ORDERBYindex_name"|tailn+2>drop.sql

After you run above query, check


step.

drop.sql

content to verify if all rows are correct. If

drop.sql

is empty, you can directly jump to next

If all looks good, run following to drop all fulltext indexes in one go:
mysqlfdb_wordpress<drop.sql

For all databases version use:


mysqlf<drop.sql

MyISAM to InnoDB
Below is a syntax to change storage engine of

wp_posts

and

wp_postmeta

tables to InnoDB.

ALTERTABLEwp_postsENGINE=InnoDB;
ALTERTABLEwp_postmetaENGINE=InnoDB;

For all tables in ONE database


If you want to covert all your MySQL tables, then run a command like below on database

db_wordpress

mysqle"SELECTconcat('ALTERTABLE',TABLE_NAME,'ENGINE=InnoDB;')
FROMInformation_schema.TABLES
WHERETABLE_SCHEMA='db_wordpress'ANDENGINE='MyISAM'ANDTABLE_TYPE='BASETABLE'"|tailn+2>alter.sql

For all tables in ALL databases


Alternatively, if you wish to covert all tables from all databases (except mysql database itself), you can use following query:
mysqle"SELECTconcat('ALTERTABLE\`',TABLE_SCHEMA,'\`.',TABLE_NAME,'ENGINE=InnoDB;')
FROMInformation_schema.TABLES
WHERETABLE_SCHEMA!='mysql'ANDENGINE='MyISAM'ANDTABLE_TYPE='BASETABLE'"|tailn+2>alter.sql

After you run above query, check

alter.sql

content to verify if all rows are correct. If

alter.sql

is empty, you probably do not have a

table using MyISAM engine.


If all looks good, run following to convert all mysql tables to InnoDB.
mysqlfdb_wordpress<alter.sql

For all databases version use:


mysqlf<alter.sql

Troubleshooting:
Most likely you will not need to troubleshoot anything. Still, if you get following error:
ERROR 1071 (42000) at line 1: Speci ed key was too long; max key length is 767 bytes InnoDB doesnt allow primary key wider than 767
bytes
Then you need to change primary key column for that mysql table. Most likely you did not speci ed any primary key and by default
InnoDB picks rst column as primary-key. You can add an auto increment column and set it as primary-key and then retry running
MyISAM to InnoDB conversion.

2016 - rtCamp Solutions Private Limited

You might also like