Convert charset in all schemas within an instance

Tags: , , ,

CONVERT ALL THE THINGS.

Well, almost all the things.

#!/bin/bash
 
for database in aaaaa bbbbb ccccc ddddd eeee
do
        thesetables=`mysql -N -B -e "SELECT CONCAT(TABLE_SCHEMA,'.',TABLE_NAME) \
           FROM information_schema.TABLES where TABLE_SCHEMA = \"$database\"" \
           AND TABLE_SCHEMA NOT IN ('mysql','information_schema','performance_schema')`
        alltables=`echo $alltables $thesetables`
        # change the schema itself
        mysql -e "ALTER DATABASE $database CHARACTER SET utf8 COLLATE utf8_general_ci;"
 
done
 
 
for table in $alltables
do
 
        echo $table
        echo "---------------------------"
        mysql -N -B -e "ALTER TABLE $table DEFAULT CHARACTER set utf8 collate utf8_general_ci;"
        mysql -N -B -e "ALTER TABLE $table CONVERT TO CHARACTER set utf8 collate utf8_general_ci;";
done