mysql set utf8 character set

Because most of the commands in the online materials contain Chinese or spaces, I have to edit them every time I copy and paste them to run, so I will sort them out.

First connect to mysql and check the character set:

mysql> 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                                              | 

| character_sets_dir       | /Volumes/mac/data/web/mysql/share/mysql/charsets/ | 

+--------------------------+---------------------------------------------------+

8 rows in set (0.01 sec)

 

mysql> show variables like "%collation_%";

+----------------------+-----------------+

| Variable_name        | Value           |

+----------------------+-----------------+

| collation_connection | utf8_general_ci | 

| collation_database   | utf8_general_ci | 

| collation_server     | utf8_general_ci | 

+----------------------+-----------------+

3 rows in set (0.00 sec)

 

If the above statement is executed and found that it is not utf8, then open the my.cnf loaded by mysql, usually in /etc/my.cnf, edit it in:

Add two lines below [mysqld]:

character_set_server = utf8

default-character-set = utf8

 

Add a statement below [mysqld_safe]:

default-character-set = utf8

 

Add a statement below [mysql]:

default-character-set = utf8

 

Add a statement below [mysql.server]:

default-character-set = utf8

 

This ensures that the character set of the database started by mysql.server is utf8, the mysql command line connection is utf-8, and the default character set of all processes is utf8, so that the operation table or database does not need to care about the character set, all are utf -8's.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326722104&siteId=291194637