BitterSweetJaVa

May 6, 2009

MySQL, change column encoding

Filed under: MySQL — Tags: , — .|2ic|K @ 10:41 PM

I was having a problem when using characters with accents in a web application. After spending some time investigating the issue, I found out that the problem was in the default encoding applied by MySQL in the tables. I solved the issue using the following command to change the encoding of the desired column (I’ll convert the entire DB in the future):

UPDATE [Table] SET [column] = CONVERT(CONVERT(CONVERT([column] USING latin1) USING binary) USING utf8);

Note that It converts the data first from latin1 to binary and then from binary to utf8.

Now the web application is showing the appropriate characters.

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.