在学MySQL的insert插入语句时,出现了下面这种问题:
insert into stu(sid,name,gender,age,birth,address,score) values(1001,'张三','男',18,'2001-12-23','北京',85.5)
> 1366 - Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'name' at row 1
> 时间: 0s
报错原因:我的数据库是utf8形式的,这种情况无法正常编码中文
解决办法:删除库,新建一个数据库以及新建表,并且在建立的过程中设置编码格式为utf8mb4
create database bi DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;;
show databases;
-- alter database bi character set utf8mb4;
use bi;
-- 创建表
create table if not exists student(
sid int,
name varchar(20),
gender varchar(20),
age int,
birth date,
address varchar(20),
score double
)default charset=utf8mb4;
-- alter table student character set utf8mb4;
insert into student(sid,name,gender,age,birth,address,score)values(1001,'张三','男',18,'2001-12-23','北京',85.5)
运行正常
参考链接:
https://blog.csdn.net/Nanran6/article/details/137155224?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-1-137155224-blog-121398385.235v43pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.2&utm_relevant_index=2