mysql出现ncorrect string value: '\xF0\x9F...' for column 'XXX' at row 1

1)、修改数据库的编码为utf8bm4

# vi /etc/my.cnf

[client]

default-character-set = utf8mb4

 

[mysql]

default-character-set = utf8mb4

 

[mysqld]

character-set-client-handshake = FALSE

character_set_server = utf8mb4

collation-server = utf8mb4_unicode_ci

init_connect='SET NAMES utf8mb4'

 

重启服务

systemctl restart mysqld.service 

 

2)、修改数据表的编码为utf8bm4

mysql> ALTER DATABASE voice_reports_test CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

mysql> ALTER TABLE ZSCC_WRK_BSE_CKLCC CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_bin; 

 

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

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

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

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

10 rows in set (0.00 sec)

 

3)、修改连接数据库的连接代码

你可能感兴趣的:(mysql,编码,数据库)