Skip to content

Instantly share code, notes, and snippets.

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 dannygsmith/9e5a57f5fa22f6c47723e4385142b80e to your computer and use it in GitHub Desktop.
Save dannygsmith/9e5a57f5fa22f6c47723e4385142b80e to your computer and use it in GitHub Desktop.
WordPress: Script to convert MySQL collation from utf8mb4 to utf8 (via http://ben.lobaugh.net/blog/201740/script-to-convert-mysql-collation-from-utf8mb4-to-utf8)
DB="your_database_name"
USER="your_db_user"
PASS="your_db_pass"
HOST="database_hostname"
(
echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'
mysql -p $PASS -u $USER -h $HOST "$DB" -e "SHOW TABLES" --batch --skip-column-names \
| xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'
) \
| mysql -p $PASS -u $USER -h $HOST "$DB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment