Tag Archives: MySQL character set error resolution

MySQL character set error resolution: err=Error 3988: Conversion from collation utf8mb4_unicode_ci into utf8_general_ci impo

The content of a field contains expressions. When inserting mysql, you will be prompted with an error:

err=Error 3988: Conversion from collation utf8mb4_unicode_ci into utf8_general_ci impossible for parameter

solve:

1. Modify MySQL character set

I am using docker

  1. Modify mysql.cnfmaps to docker where /etc/mysql/mysql.cnf:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
      1. start command parameter addition:
 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

After restarting the container, enter Mysql to view:

mysql> 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     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
| collation_connection     | utf8mb4_unicode_ci             |
| collation_database       | utf8mb4_unicode_ci             |
| collation_server         | utf8mb4_unicode_ci             |
+--------------------------+--------------------------------+
11 rows in set (0.17 sec)

2. Modify the character set of table

        1. modify the character set of a specific table:
DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
          1. modify the character set of a specific field:
CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci