报错Incorrect string value: ‘\xE5\xAD\x99\xE4\xBD\xB3...‘ for column ‘username‘ at row 1

Main error content
### SQL: insert into t_account(username,password,age) values(?,?,?)
Incorrect string value: '\xE5\xAD\x99\xE4\xBD\xB3...' for column 'username' at row 1
Reason for error:

The character set encoding format when building the database and the table does not match, the sqlyog client, if not selected when building the table, the default encoding of the field is Latin1, which can be passed through the mysql command line (note that the semicolon must be added at the end of the command line statement!! !) View

show create table 表名;
Solution:
1. Set the default string encoding method to utf8 when creating the table
CREATE TABLE test2(
.........# 内容
)default charset = utf8;      # 建立一个表,加上“default charset = utf8”,设置默认字符串编码方式为utf8。
2. The added table needs to be set up:ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE 表名 CONVERT TO
CHARACTER SET utf8 COLLATE utf8_unicode_ci;    # 例如刚刚建立的test表,插入中文时会报错,现在对其进行设置
3. Modify the string encoding properties of the database directly:ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci
ALTER DATABASE 数据库名 CHARACTER
SET utf8 COLLATE utf8_unicode_ci;  # 修改数据库testdb的编码方式
CREATE TABLE 表名(
........ # 内容
)default charset = utf8;  # 建立一个表,加上“default charset = utf8”,设置默认字符串编码方式为utf8。

Reference link

Guess you like

Origin blog.csdn.net/weixin_45845039/article/details/114573207
Recommended