Thursday, November 3, 2016

Change the Group-Office database collation and character set

Recently we converted the Group-Office database to the collation "utf8mb4_unicode_ci". We did this to support 4 byte unicode characters. Some customers may want to use another collation because of sorting in the database. For example Danish users want to use "utf8mb4_danish_ci". You can choose any collation as long as it starts with "utf8mb4".
You can use this bash script to convert all tables in the database.
Make a backup first!
#!/bin/bash
DB="go61mb4"
COLLATE="utf8mb4_unicode_ci"
USER="root"
PASSWORD="SECRET"

(
  echo 'set foreign_key_checks=0;ALTER DATABASE `'"$DB"'` \
  CHARACTER SET utf8mb4 COLLATE '"$COLLATE"';'
  mysql -u "$USER" -p"$PASSWORD"  "$DB" -e "SHOW TABLES" --batch --skip-column-names \
  | xargs -I{} echo 'ALTER TABLE `'{}'` \
  CONVERT TO CHARACTER SET utf8mb4 COLLATE '"$COLLATE"';'
) \
| mysql -u "$USER" -p"$PASSWORD" "$DB"

Change the Group-Office database collation and character set

Recently we converted the Group-Office database to the collation "utf8mb4_unicode_ci". We did this to support 4 byte unicode characters. Some customers may want to use another collation because of sorting in the database. For example Danish users want to use "utf8mb4_danish_ci". You can choose any collation as long as it starts with "utf8mb4".
You can use this bash script to convert all tables in the database.
Make a backup first!
#!/bin/bash
DB="go61mb4"
COLLATE="utf8mb4_unicode_ci"
USER="admin"
PASSWORD="mks14785"

(
  echo 'set foreign_key_checks=0;ALTER DATABASE `'"$DB"'` \
  CHARACTER SET utf8mb4 COLLATE '"$COLLATE"';'
  mysql -u "$USER" -p"$PASSWORD"  "$DB" -e "SHOW TABLES" --batch --skip-column-names \
  | xargs -I{} echo 'ALTER TABLE `'{}'` \
  CONVERT TO CHARACTER SET utf8mb4 COLLATE '"$COLLATE"';'
) \
| mysql -u "$USER" -p"$PASSWORD" "$DB"