Jump to content

Recommended Posts

I've been given a database where some text columns are using latin encoding (or swedish? ugh). I want to update these columns to utf encoding while preserving the data to be accessed correctly after the column type is changed. What are the steps? Do I convert the data FIRST and then alter the column encoding type? Or vice-versa? Or something else?

 

Also, is this the best way to update the data?

convert(cast(convert(column_name using latin1) as binary) using utf8)

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/284779-character-set-issues/
Share on other sites

Sorry, another question on this, because I'm not sure I asked it correctly the first time: The database column is currently latin1_swedish BUT the encoding used by the application's mysql connection is UTF-8.

 

This is why I was wondering about needing to convert data before converting the column.

MySQL will still convert it for you. At the very least try to: if there's a character in the first character set that's not available in the second then you will lose some data (IIRC), but that's not going to be an issue with Latin1 -> UTF-8 (since MySQL's utf8mb3 contains all of the characters in latin1).

 

[edit] But since the reverse is not true, you should check your data to make sure it's all correct: if you tried to save something not valid in Latin1 then MySQL couldn't have saved it correctly and you'll need to fix it manually (since the data would have been lost).

Edited by requinix
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.