Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Sql Second Generation Utf8Mb4 Encoding

We are using Google Cloud Sql Second Generation with our AppEngine application. However today we've discovered some problem, we cannot insert emoji characters to our database because we cannot change some server flags to utf8mb4 character encoding.

We've changed character_set_server flag to utf8mb4 but it wasnt enough

We have to change: character_set_system character_set_client collaction_connection

flags to utf8mb4 also, but second generation db is not allowing root user to change those flags. What can we do to solve this problem

Does anyone have any idea about that?

Thanks

like image 208
tolgatanriverdi Avatar asked Aug 10 '16 14:08

tolgatanriverdi


2 Answers

You have to set character_set_server to utf8mb4, change the columns you need to utf8mb4 and create a new Cloud SQL 2nd gen instance with the new flag (!!). Basically, setting the flag on an existing instance and just restarting (tested with 5.7) will not be enough (is this a bug? I did not find it in the docs). Any encoding related connection parameters are not needed and should be removed. The collation will be the standard collation for utf8mb4 which is perfect for me (and probably most cases), even without setting anything.

like image 168
cputoaster Avatar answered Oct 08 '22 00:10

cputoaster


We had the exact same problem. Setting character_set_server to utf8mb4 wasn't enough. We could insert emojis through MySQL Workbench, but not through our application.

In our case, this problem went away after we started a new instance running MySQL 5.7 instead of 5.6. So my hypothesis is that in 5.7, but not in 5.6, changing the character_set_server flag lets Google Cloud SQL change those other flags you mention, or some other relevant setting.

Of course if you are already running 5.7, this does not apply to you.

like image 1
oulenz Avatar answered Oct 08 '22 01:10

oulenz