Skip to content

Instantly share code, notes, and snippets.

@juliushaertl
Created October 26, 2016 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save juliushaertl/b0d229a2fe79513397be1dc423dce82c to your computer and use it in GitHub Desktop.
Save juliushaertl/b0d229a2fe79513397be1dc423dce82c to your computer and use it in GitHub Desktop.
convert a mysql table to utf8mb4 (useful for migration to mb4 on Nextcloud)
#!/bin/bash
#
# CHANGE VALUES OF DATABASE AND MYSQL TO MATCH YOUR SETUP
DATABASE="devncmaster"
MYSQL="mysql -N --database=$DATABASE"
# convert database with all tables to utf8mb4
echo "ALTER DATABASE $DATABASE CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin;" | $MYSQL
echo 'show tables' | eval $MYSQL | while read table
do
echo "ALTER TABLE $table ROW_FORMAT=DYNAMIC;" |
eval $MYSQL
echo "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;" |
eval $MYSQL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment