当前位置:网站首页>MySQL storage expression error

MySQL storage expression error

2022-07-07 20:52:00 The wind continues to blow 1943

Preface

  • operating system :linux
  • Database version : 8.0.27
  • View version commands :mysql -uroot -p After logging in successfully, you can see

problem

Personal blog markdown The following error is reported after inserting the label

Error message :Incorrect string value: '\\xF0\\x9F\\x98\\x82' for column 'content' at row 1

I found out on the Internet that : In use mysql When storing emoticons , Will report a mistake , This is because Emoji The expression is 4 Bytes , and mysql Of utf-8 The code is at most 3 Bytes , So when inserting emoticons, they will not be inserted . At this time, it should be modified mysql Encoded as utf8mb4 To solve the problem .

But I am sql This has been thought of when creating the table, and the related fields are also utf8mb4, Why do you report errors

image.png

Check and solve

Through multiple queries and attempts , Found as long as you modify mysql Configuration information can solve the problem

1. stay linux Find below mysql Configuration file for my.cnf (window by my.ini), If you can't find it, you can directly query

$ find / -name my.cnf

2. stay my.cnf Edit

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

3. restart mysql service

$ service mysqld restart

mysql Variable configuration extension

1.character_set_client It is mainly used to set the character set used by the client .

2.character_set_connection It is mainly used to set the character set when connecting to the database , If the type of character set used to connect to the database is not specified in the program, set it according to this character set .

3.character_set_database It is mainly used to set the encoding format of the default creation database , If the encoding format is not set when creating the database , Just follow this format .

4.character_set_filesystem File system encoding format , Convert the file name on the operating system to this character set , Namely the character_set_client transformation character_set_filesystem, Default binary There is no conversion .

5.character_set_results The encoding format used when the database returns to the client , If there is no indication , Use the server's default encoding format .

6.character_set_server The default encoding format specified when the server is installed , This variable is recommended to be managed by the system itself , Don't artificially define .

7.character_set_system The coding format used by the database system , This value has always been utf8, You don't have to set it , It's the encoding format for storage system metadata .

8.character_sets_dir This variable is the directory where the character set is installed .

原网站

版权声明
本文为[The wind continues to blow 1943]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071954098726.html