Skip to content

Instantly share code, notes, and snippets.

@dylanjameswagner
Forked from rogeruiz/utf8mb4_to_utf8
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save dylanjameswagner/b005af8434a9f10b3149 to your computer and use it in GitHub Desktop.

Select an option

Save dylanjameswagner/b005af8434a9f10b3149 to your computer and use it in GitHub Desktop.
WordPress 4.2 adds utf8mb4 collation to MYSQL servers that support it when it runs update.php. It's very likely that your development machine is running the latest MYSQL version and you'll need to revert back to the DB collation that you had before 4.2 to support older verisons of MYSQL when doing a database migration. If you have WordPress inst…
#!/bin/bash
DB_NAME="wordpress_test"
DB_USER_NAME="external"
DB_PASSWORD="external"
DB_HOST="vvv.dev"
DB_PORT="3306"
(
echo "ALTER DATABASE ${DB_NAME} CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=$DB_USER_NAME \
--password=$DB_PASSWORD \
--host=$DB_HOST \
--port=$DB_PORT \
--batch \
--skip-column-names \
-e "SHOW TABLES" \
--database=$DB_NAME |
xargs -I%DB_NAME% \
echo "ALTER TABLE %DB_NAME% CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"
) |
mysql --user=$DB_USER_NAME \
--password=$DB_PASSWORD \
--host=$DB_HOST \
--port=$DB_PORT \
--database=$DB_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment