Solve the problem related to mysql inserting Chinese Characters in centos 7

Source: Internet
Author: User

Solve the problem related to mysql inserting Chinese Characters in centos 7

After mysql is installed, the database abc is created, and a new abc table is created. There is no problem in English language insertion, but there is a problem in Chinese language insertion, and 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 we should change the database encoding.

Here is the method in 2. One is to directly knock on the Code settings, the other is to modify the file/usr/my. cnf in CentOS7,

Method 1:

List database encoding tables

Mysql> show variables like '% char % ';

Modify the encoding format:

Mysql> set character_set_database = utf8;

Mysql> set character_set_server = utf8;

And so on

That is, keep the original default values of character_set_filesystem and character_sets_dir unchanged, and change all other values to utf8.

Then, delete the original database and create a new table. Then, you can insert Chinese characters into the table...

Method 2: 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 ]:

[Mysqld]

Character_set_server = utf8

[Mysql]

Default-character-set = utf8

[Client]

Default-character-set = utf8

Note:

Shortcut keys used to edit files:

Enter edit mode
I
Exit edit mode
Esc
Exit the file and save it.
: Wq

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.