Home  >  Article  >  Database  >  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
PHPzforward
2023-05-31 20:49:041258browse

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%';

Modify the encoding format:

mysql> set character_set_database=utf8;

mysql> set character_set_server=utf8;

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

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete