-1

I want to convert my current MySQL database encoded with latin1 to a new database encoded with utf-8.

How could I import my old data (text fields) correctly to the tables of the new database with utf-8 encoding? I thought I can use a query as follows:

insert into newTable (newField) select latin2utf8(oldField) 
from oldTable

What I am looking for is a SQL function or a combination of functions which works as latin2utf8 mentioned in the query.

Is there any SQL method for converting data as I described, to be used in this command?

Ahmad
  • 8,811
  • 11
  • 76
  • 141
  • 1
    Please consider my modified question and answer, the problem is clearly stated! – Ahmad Dec 13 '14 at 09:46
  • 2
    This is being discussed on [Meta](http://meta.stackoverflow.com/questions/284934/my-question-was-closed-while-a-similar-question-is-open-a-poin-on-the-problem). It was deleted, but I've undeleted it to facilitate discussion on it. – Andrew Barber Jan 30 '15 at 14:28

1 Answers1

4

In the query that is reading rows from the old database, first, convert the column to binary, then convert it back to utf8 as follows:

select convert(binary convert(field_name using latin1) using utf8) 
from table_name
Kendra
  • 769
  • 1
  • 20
  • 34
Ahmad
  • 8,811
  • 11
  • 76
  • 141