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

Tutorial on resetting the root password of Mac MySQL

Disclaimer: This password reset method can direct...

What is this in JavaScript point by point series

Understand this Perhaps you have seen this in oth...

MySQL stored procedures and common function code analysis

The concept of mysql stored procedure: A set of S...

Common operation commands of MySQL in Linux system

Serve: # chkconfig --list List all system service...

Solution to data duplication when using limit+order by in MySql paging

Table of contents summary Problem Description Ana...

How to set up a deployment project under Linux system

1. Modify the firewall settings and open the corr...

Tutorial on using $attrs and $listeners in Vue

Table of contents introduce Example Summarize int...

Example of implementing a virtual list in WeChat Mini Program

Table of contents Preface analyze Initial Renderi...

JavaScript typing game

This article shares the specific code of JavaScri...

Complete step record of Vue encapsulation of general table components

Table of contents Preface Why do we need to encap...

Detailed explanation of Vue development Sort component code

Table of contents <template> <ul class=&...

Introduction to MySQL statement comments

MySQL supports three types of comments: 1. From t...

js implements clock component based on canvas

Canvas has always been an indispensable tag eleme...