mochahochabeachside.com

MySQL Oneliner to change collation/charset

by 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]

:
No comments for this entry yet...

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...