我从问题Incorrect string value: '\xF0\x9F\x8E\xB6\xF0\x9F...' MySQL的最佳答案中做了同样的事情 但是在运行之后
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
我还有:
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server latin1
character_set_system utf8
collation_connection utf8mb4_general_ci
collation_database utf8mb4_general_ci
collation_server latin1_swedish_ci
实际上我想把它设置为:
character_set_client utf8mb4
character_set_connection utf8mb4
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8mb4
character_set_server latin1
character_set_system utf8
collation_connection utf8mb4_general_ci
collation_database utf8mb4_unicode_ci
collation_server utf8mb4_unicode_ci
我该怎么办?或者我可以只设置一个表或一列的字符集吗?
更新: 我仍然不知道如何只设置一个表或列,但我使用下面的代码来设置整个数据库:
set character_set_database = utf8mb4;
我已经将数据库的character_set_ *和collation_ *设置为我想要的,我甚至设置了指定表的character_set和collation,但我仍然在线程" main&#34中得到了Exception。 ; java.sql.BatchUpdateException:字符串值不正确:' \ xF0 \ x9F \ x98 \ x98 T ...'。同时,我没有在具有相同结构的另一个数据库上得到类似的错误。有谁猜到了原因?
-------------再次更新--------------
我通过在数据库配置文件my.cnf中添加以下代码来解决它:
# Set coding to support multi-language.
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect = 'SET NAMES utf8mb4'