MySQL Oneliner to change collation/charset
by Eric on Feb.02, 2009, under One-liners
This little one-liner will automatically change the collation and character set for every table in a database, including the database itself. The only thing it doesn't do is change the collation/charset of the individual columns in a table (I have yet to find a one-liner that works for that, but I keep trying).
for i in `mysqldump --add-drop-table --no-data DBNAME | grep ^DROP | awk '{print $5}' | cut -d\\\` -f2`;do mysql -e "ALTER TABLE ${i} CHARACTER SET charset COLLATE coll_ati_on;" DBNAME;done && mysql -e "ALTER DATABASE database CHARACTER SET charset COLLATION coll_ati_on;" DBNAME
If you happen to come up with something to do the columns as well, for the love of all that's holy, let me know.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=c6664d08-e448-4904-872e-1d77522b37c6)




