Home > Database > Mysql Tutorial > How to solve the error when inserting Chinese characters into mysql under centOS7

How to solve the error when inserting Chinese characters into mysql under centOS7

PHPz
Release: 2023-05-31 20:49:04
forward
1292 people have browsed it

After I just installed mysql, I created the database abc, and then created a new abc table. There is no problem inserting English, but there is a problem inserting Chinese. An error will be reported:

error 1366 (hy000): incorrect string value: '\xe4\xbd\x99\xe9\x93\xb6...'

It should be a database encoding problem, so the database encoding should be changed

There are 2 methods here. One is to set the code directly, and the other is to modify the file /usr/my.cnf in centos7,

The first method:

List the database Encoding table

mysql> show variables like '%char%';
Copy after login

Modify the encoding format:

mysql> set character_set_database=utf8;

mysql> set character_set_server=utf8;
Copy after login

etc

Just keep the original default values ​​of character_set_filesystem and character_sets_dir unchanged, and change everything else to utf8

Then delete the originally created database and create a new one, and then create a table to insert Chinese characters. . .

Second method: Modify the file /usr/my.cnf in centos7,

Open the configuration file:

vi /etc/my .cnf;

Add the following content under [mysqld], [mysql], and [client] respectively

[mysqld]

character_set_server = utf8

[mysql]

default-character-set=utf8

[client]

default-character-set=utf8
Copy after login

Remarks:

Shortcut keys for editing files:

Enter edit mode edit

i

Exit edit mode

esc

Exit the file and save

:wq

The above is the detailed content of How to solve the error when inserting Chinese characters into mysql under centOS7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template