0

I have 8 tables with many fields in them all created with Latin charset.

I want to convert all of them into UTF-8.

For database and tables, I can do it manually.

How do I do it for fields programatically?

Moe Sweet
  • 3,683
  • 2
  • 34
  • 46
  • If you're not averse to some command line or php, there are some answers in this question: http://stackoverflow.com/questions/105572/a-script-to-change-all-tables-and-fields-to-the-utf-8-bin-collation-in-mysql (I personally like the command line version better...): might not be flexible enough for you though. – mathematical.coffee Dec 21 '11 at 01:20

1 Answers1

1

I would like to recommend information_schema.columns.
This is a very useful view.

To get list of the columns not in UTF-8:-

select table_schema, table_name, column_name, character_set_name, collation_name 
from information_schema.columns
where table_schema in ('YOUR_DB') and collation_name not like 'utf8%';

select table_schema, table_name, column_name, character_set_name, collation_name 
from information_schema.columns
where table_schema in ('YOUR_DB') and character_set_name not like 'utf8%';

The best thing about this view ... it also include the data type for the column (refer to COLUMN_TYPE in the doc), default value (refer to COLUMN_DEFAULT) and etc ...
with all these information, I think is pretty easy to make use on a programming language to construct the relevant SQL (and execute it)

ajreal
  • 46,720
  • 11
  • 89
  • 119