Configure Amazon RDS mysql to store Chinese characters

How do I configure Amazon RDS to properly store Chinese characters? Currently, the text is becoming "????".

I already created a new parameter group and set the character set to utf8 and changed the instance. Detailed information is provided below:

mysql> show variables like '%char%'; +--------------------------+-------------------------------------------+ | 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 | | character_sets_dir | /rdsdbbin/mysql-5.5.27.R1/share/charsets/ | +--------------------------+-------------------------------------------+ +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_unicode_ci | +----------------------+-----------------+ 
+6
source share
3 answers

After @Peter Venderberghe's answer to set up RDS, I still can't let it store Chinese characters correctly.

Finally, I used the mysql command line to connect to RDS (you can use mysql workbench or another client tool you like)

mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME

Note:

1). do not forget to add the current ip to the security group included in RDS before connecting to RDS

2). you can get related information (security groups, USERNAME ... etc.) on the RDS console except PASSWORD . PASSWORD must be the one you created for the instance. HOSTNAMEORIP - "Endpoint" (without port) on the console.

3). there is no space between -p and PASSWORD. that's for sure -pPASSWORD .

After connecting to mysql with a tool convenient for you, you need to give it a few commands:

 # set character set and collation for database mysql> alter database DATABASENAME CHARACTER SET utf8 COLLATE utf8_unicode_ci; -------- # set character set and collation for new records in a table mysql> ALTER TABLE TABLENAME CHARACTER SET utf8 COLLATE utf8_unicode_ci; # set character set and collation for existing records in a table mysql> ALTER TABLE TABLENAME CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci; 

you can write a script to complete this task if you have many tables. However, this is not included in the scope of this answer.

After setting, as described above, you can download with Chinese characters!

+13
source

If you use RDS, you can configure a parameter group for your mysql instance.

  • Create a new parameter group
  • Modify your db instance with a new parameter group
  • reload your db instance

Done! It should be pretty simple. You will see when you get there.

+5
source

Make sure you are using the UTF-8 character set.

The easiest way to set encodings forever is to update the my.cnf client as follows:

 [client] default-character-set=utf8 

Detailed information about the encoding of connections can be found here: http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

When using the functions of the MySQL API (for example, a PHP client), you can set the encoding of connections by sending a request

 SET NAMES utf8 

You can configure Amazon RDS to use the Utf-8 character set by following this blog: http://matthew.mceachen.us/blog/howto-configure-an-amazon-rds-instance-to-use-utf-8-925 .html

Hope this helps.

+2
source

Source: https://habr.com/ru/post/946639/


All Articles