Skip to content

Instantly share code, notes, and snippets.

@herewithme
Created February 20, 2019 05:38
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 herewithme/b996306d3c0f48b210d7f9d0415caed7 to your computer and use it in GitHub Desktop.
Save herewithme/b996306d3c0f48b210d7f9d0415caed7 to your computer and use it in GitHub Desktop.
Convert all WordPress tables to UTF8MB4 with WP-CLI
#!/usr/bin/env bash
# Author Amaury Balmer - BEAPI.fr
# See: https://wordpress.stackexchange.com/questions/195046/relaunch-4-2-utf8mb4-databse-upgrade/244992#244992
# Purpose - Convert all tables to UTF8MB4 with WP-CLI
# Create array of all tables
WPTABLES=($(wp db tables --all-tables))
# loop through array and alter tables
for WPTABLE in ${WPTABLES[@]}
do
echo "Converting ${WPTABLE} to UTF8MB4"
wp eval "echo maybe_convert_table_to_utf8mb4( ${WPTABLE} );" --allow-root
echo "Converted ${WPTABLE} to UTF8MB4"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment