Convert character set of MySQL database

In the command line shell, just fill in “dbname”, “user”, “pass” 😀

DB="dbname"
USER="user"
PASS="pass"
(
echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8 COLLATE utf8_general_ci;'
mysql -u "$USER" -p"$PASS" "$DB" -e "SHOW TABLES" --batch --skip-column-names \
| xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;'
) \
| mysql -u "$USER" -p"$PASS" "$DB"