Skip to content

Instantly share code, notes, and snippets.

@motammem
Created May 6, 2017 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motammem/b57a93ae986d469b8dbb6b9264130a60 to your computer and use it in GitHub Desktop.
Save motammem/b57a93ae986d469b8dbb6b9264130a60 to your computer and use it in GitHub Desktop.
Make all table and columns charset UTF-8
#!/usr/bin/env bash
############################################
# Make all table and columns charset UTF-8 #
############################################
# Replace parameters below before use
database=[database]
user=[user]
password=[password]
mysql.exe --database=${database} -u ${user} -p${password} -B -N -e "SHOW TABLES" \
| awk.exe '{print "SET foreign_key_checks = 0; ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; SET foreign_key_checks = 1; "}' \
| mysql.exe -u ${user} -p${password} --database=${database} &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment