Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL utf8mb4 on Amazon RDS: global variables set correctly but variables not set

I'm trying to convert my Amazon RDS server to use utf8mb4 encoding instead of utf8. I've followed the guide here and it has worked for the most part (global variables are set through my new parameter group in RDS), but my system variables are not setting correctly which means that I'm not able to utilize the new encoding.

When I run:

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

I see:

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8               |
| character_set_connection | utf8               |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8               |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8_general_ci    |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

Which is obviously incorrect, but when I run:

SHOW GLOBAL VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

I see:

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8mb4            |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8mb4            |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

This is correct, but for some reason these global values are not setting the server when I restart the server. I can correctly set the variables manually after restarts, but I don't understand why they aren't setting initially.

like image 759
Aaron Wojnowski Avatar asked Dec 25 '15 22:12

Aaron Wojnowski


1 Answers

To clarify Aaron's answer, this was (at least for us) caused by the character set/collation of our connection to the database; the database itself is set up correctly. When you use any client to connect to the db -- whether it be SQLyog, MySQL Workbench, built in client or any other -- there is a character set and collation associated with that connection. Thus you need to need to change this connection charset/collation to utf8mb4 and utf8mb4_unicode_ci, and the values of

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

will then all show correctly. If you take a close look at the "problem" values in the original question you'll notice they are _client, _connection etc. which should have given me an obvious clue that the problem was with my mysql client and not the database itself.

like image 109
KayakinKoder Avatar answered Nov 12 '22 07:11

KayakinKoder