Skip to content

Instantly share code, notes, and snippets.

@robinnorth
Last active August 5, 2019 13:45
Show Gist options
  • Save robinnorth/e2524a949d752f20ff3d to your computer and use it in GitHub Desktop.
Save robinnorth/e2524a949d752f20ff3d 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