The character set is the common problem while using databases. Actually, many of you do not understand use of this part, then unreadable codes may appear during use. Today, we will talk about relevant problems of character set in details, to calmly cope with unreadable codes.
Firstly, we need to log in the RDS instance to view how the character set is set up. After the database instance is remotely connected, you need to select your desirable library through commands below:
use <Library Name>
show variables like '%character%'
variable_name | value |
---|---|
character_set_client | utf8 |
character_set_connection | utf8 |
character_set_database | utf8 |
character_set_filesystem | binary |
character_set_results | utf8 |
character_set_server | utf8 |
character_set_system | utf8 |
This parameter can be set by the client, and please refer to the following explanation for specific setting method.
This parameter can be set by the client, and please refer to the following explanation for specific setting method.
This parameter value is related to the character set designated while creating a library. For how to designate the character set while creating a library, please refer to Create Library
Do not worry about this parameter
This parameter can be set by the client, and please refer to the following explanation for specific setting method.
The parameter is the server setting and its value can be modified via the parameter set, with reference of Modify Parameter; note: be sure to reboot instance after modifying this parameter, to keep the default value character_set_database
and character_set_server
synchronized.
Do not worry about this parameter
As mentioned above, the three parameters, character_set_client
, character_set_connection
and character_set_results
are session-level, which can be set via the client. After the JD Cloud Onboarding RDS instances are connected, please execute the following SQL instructions:
set names <Character Set Code>;
Note: Because the parameter value are session-level, the original character set will become invalid after the database instance is reconnected. In this case, please set by executing the set names
command again.
To avoid unreadable codes while using the database, please be sure to keep the four parameter values consistent, i.e. character_set_client
, character_set_connection
, character_set_results
and character_set_database
. If not, unreadable codes may appear.
If you need to save the emoji expression in RDS instances, please be sure to save character_set_client
, character_set_connection
, character_set_results
and character_set_database
, each of the four parameter sets is utf8mb4.
c++ example codes of character set via the client are as shown below and are for reference only
string sql = "set names utf8mb4"; mysql_query(connection, sql.c_str());