Convert Charset In All Schemas Within An Instance

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: