Skip to content

Instantly share code, notes, and snippets.

@pioz
Created September 10, 2019 09:57
Show Gist options
  • Select an option

  • Save pioz/a948aeeda51a75e996f1cd3b7f1afcc7 to your computer and use it in GitHub Desktop.

Select an option

Save pioz/a948aeeda51a75e996f1cd3b7f1afcc7 to your computer and use it in GitHub Desktop.
Convert database charset encoding to utf8mb4 and collation to utf8mb4_unicode_ci
#!/bin/bash
DB="italian_spiderman"
CHARSET="utf8mb4"
COLL="utf8mb4_unicode_ci"
echo $DB
echo "ALTER DATABASE \`$DB\` CHARACTER SET $CHARSET COLLATE $COLL;" | mysql
echo "USE \`$DB\`; SHOW TABLES;" | mysql -s | (
while read TABLE; do
echo $DB.$TABLE
echo "ALTER TABLE \`$TABLE\` CONVERT TO CHARACTER SET $CHARSET COLLATE $COLL;" | mysql $DB
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment