Skip to content

Instantly share code, notes, and snippets.

@rogeruiz
Last active August 29, 2015 14:21
Show Gist options
  • Save rogeruiz/ad521a1becc13c2d9a92 to your computer and use it in GitHub Desktop.
Save rogeruiz/ad521a1becc13c2d9a92 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%TABLE_NAME% \
echo "ALTER TABLE %TABLE_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
@rogeruiz
Copy link
Author

just download the Gist, make the file executable using chmod ug+x ./utf8mb4_to_utf8, update the variables on lines 3-7, and run the script in the terminal ./utf8mb4_to_utf8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment