Skip to content

Instantly share code, notes, and snippets.

@schuhwerk
Last active March 5, 2021 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schuhwerk/4d8005bdf0af328e0c6130ca31aa7a9f to your computer and use it in GitHub Desktop.
Save schuhwerk/4d8005bdf0af328e0c6130ca31aa7a9f to your computer and use it in GitHub Desktop.
Convert tables (WordPress) to innodb. Run multiple at once...
#!/usr/bin/env bash
# Original Author Mike https://guides.wp-bullet.com
# Edited by Vitus Schuhwerk
# Purpose - Convert MyISAM tables to InnoDB with WP-CLI
# You can run multiple instances of this like this:
# - "bash scriptname 4 0" convert tables 0, 4, 8, ...
# - "bash scriptname 4 1" convert tables 1, 5, 9, ...
# - "bash scriptname 4 2" convert tables 2, 6, 10, ...
# - "bash scriptname 4 3" convert tables 3, 7, 11, ...
QUERY="SELECT TABLE_NAME from information_schema.tables infs WHERE infs.Engine='MyISAM' AND regexp_substr( TABLE_NAME, '[0-9]+' ) % $1 = $2;"
# create array of MyISAM tables
WPTABLES=($(wp db query "$QUERY" | awk '{ print $1}'))
# loop through array and alter tables
for WPTABLE in ${WPTABLES[@]}
do
wp db query "ALTER TABLE ${WPTABLE} ENGINE=InnoDB"
echo "Converted ${WPTABLE} to InnoDB"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment