LLLLLLL Posted December 15, 2013 Share Posted December 15, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/ Share on other sites More sharing options...
requinix Posted December 15, 2013 Share Posted December 15, 2013 MySQL will convert it for you. Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/#findComment-1462393 Share on other sites More sharing options...
LLLLLLL Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) You mean I just have to alter the column type and the conversion occurs automagically? Edited December 15, 2013 by timneu22 Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/#findComment-1462413 Share on other sites More sharing options...
requinix Posted December 16, 2013 Share Posted December 16, 2013 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/#findComment-1462417 Share on other sites More sharing options...
LLLLLLL Posted December 16, 2013 Author Share Posted December 16, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/#findComment-1462476 Share on other sites More sharing options...
requinix Posted December 16, 2013 Share Posted December 16, 2013 (edited) 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 December 16, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/284779-character-set-issues/#findComment-1462480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.