Solution to ERROR 1366 when entering Chinese in MySQL

Solution to ERROR 1366 when entering Chinese in MySQL

The following error occurs when entering Chinese in MySQL:

ERROR 1366: 1366: Incorrect string value: '\xE6\xB0\xB4\xE7\x94\xB5...' for column 'introduce' at row 1

This is because of mysql encoding problem

Open mysql

mysql -u root -p

After entering the password, enter the following line of code to display the encoding currently used by MySQL:

SHOW VARIABLES LIKE 'character%'; 

From above

As can be seen from the figure, the character sets of the database and server use the latin1 encoding method. The latin1 encoding does not support Chinese, so errors will occur when storing Chinese.

Solution: Modify /etc/mysql/my.cnf (this is the default installation path of mysql)
After opening my.cnf, add the following lines of code under [mysqld] in the file:

[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
[mysql]
default-character-set=utf8

Save and exit.

Restart mysql service

service mysql restart

Now delete the problematic table in MySQL and rebuild it to solve the problem.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • mysql ERROR 1044 (42000): Access denied for user ''''@''localhost'' to database
  • ERROR 2002 (HY000): Can't connect to local MySQL server through socket ''/tmp/mysql.sock''
  • How to solve mysql error 1819 (HY000)
  • Solution to SQL Error (2013) connection error in MySQL
  • MySQL bypasses granting information_schema objects and reports ERROR 1044 (4200) error

<<:  How to obtain and use time in Linux system

>>:  7 interview questions about JS this, how many can you answer correctly

Recommend

The difference between MySQL count(1), count(*), and count(field)

Table of contents 1. First look at COUNT 2. The d...

MySQL 5.5.27 installation graphic tutorial

1. Installation of MYSQL 1. Open the downloaded M...

Vue implements a simple magnifying glass effect

This article example shares the specific code of ...

About the selection of time date type and string type in MySQL

Table of contents 1. Usage of DATETIME and TIMEST...

Some points on using standard HTML codes in web page creation

The most common mistake made by many website desi...

Vue+el-table realizes merging cells

This article example shares the specific code of ...

MySQL paging analysis principle and efficiency improvement

MySQL paging analysis principle and efficiency im...

Example steps for using AntV X6 with Vue.js

Table of contents 0x0 Introduction 0x1 Installati...

Example of using docker compose to build a consul cluster environment

Basic concepts of consul Server mode and client m...

How to use CocosCreator for sound processing in game development

Table of contents 1. Basics of audio playback in ...

The difference between Div and table in HTML (discussed in detail in all aspects)

1: Differences in speed and loading methods The di...

A complete record of a Mysql deadlock troubleshooting process

Preface The database deadlocks I encountered befo...