Last active
March 5, 2021 20:02
-
-
Save schuhwerk/4d8005bdf0af328e0c6130ca31aa7a9f to your computer and use it in GitHub Desktop.
Convert tables (WordPress) to innodb. Run multiple at once...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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