Seems like I'm dealing with a fairly common problem. My production MySQL database has a default charset and collation of latin1
/latin1_swedish_ci
. I neglected to change it early on, and my Rails app has grown to a decent size with an international audience; non-english characters cause exceptions to be thrown while emojis display as question marks.
I know I have a large task ahead of me to convert to utf8mb4
/utf8mb4_general_ci
. From what I understand if I just run something like this my data could end up compromised.
It seems fairly straightforward to change the database-wide charset/collation like this:
ALTER DATABASE mydbname CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
My question is, will changing JUST the database charset/collation immediately affect reads & writes? Or does that just establish what encoding gets applied when new tables are created within the database?
If I want to eventually convert all my tables it seems like step one would be to deal with the database-wide level first... but what side-effects will that have immediately?