当前位置:网站首页>MySQL 因字符集问题插入中文数据时提示代码 :1366
MySQL 因字符集问题插入中文数据时提示代码 :1366
2022-06-24 07:05:00 【梦凝哲雪】
错误代码
Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89...' for column `books` at row 1
原因分析
MySQL在安装数据库时 如若未指定utf-8字符集时 默认字符集为latin1
后续新建数据库,如果只写数据库名,没有设置字符集和排序规则,默认字符集为latin1 ,排序规则为latin1_swedish_ci 。
而latin1是不支持中文的,故插入中文会所有错误代码 1366
查看mysql当前编码
show variables like 'character%';

解决办法
重新创建数据库命令如下:
CREATE DATABASE `books` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
或者修改数据库字符集命令如下:
alter database books character set utf8;
修改完成数据库字符集,重启数据库,然后在修改表字符集命令如下:
ALTER TABLE 表名 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
在修改列字符集,命令如下:
ALTER TABLE 表名 CHANGE 列名 列名 VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
注:如果我们在数据库要存储中文数据,创建数据库时千万别忘了设置utf-8字符集。
边栏推荐
- mysql组合索引的有序性
- Several schemes of PHP code encryption
- MATLAB Camera Calibrator相机标定
- Rust procedure macro simply imitates Lombok function
- 2021-06-25: a batch of strings consisting only of lowercase letters (a~z) are put
- Promise usage scenarios
- Fund raising, trading and registration
- ZUCC_编译语言原理与编译_实验04 语言与文法
- How to replace the web player easyplayerproactivex Key in OCX?
- Video Fusion communication has become an inevitable trend of emergency command communication. How to realize it based on easyrtc?
猜你喜欢

Longhorn installation and use

ZUCC_ Principles of compiling language and compilation_ Experiment 01 language analysis and introduction

2021-03-16 comp9021 class 9 notes

Opencv实现图像的基本变换

日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用

MATLAB Camera Calibrator相机标定

2021-03-09 comp9021 class 7 Notes
![[micro services ~nacos] Nacos service providers and service consumers](/img/b7/47ecd6979ccfeb270261681d6130be.png)
[micro services ~nacos] Nacos service providers and service consumers

5分钟,客服聊天处理技巧,炉火纯青

Redis的Cluster集群数据倾斜
随机推荐
ZUCC_编译语言原理与编译_实验03 编译器入门
JS to get the last element of the array
2022 mobile crane driver special operation certificate examination question bank and online simulation examination
Take my brother to do the project. It's cold
Easydss anonymous live channel data volume instability optimization scheme sharing
Tencent conference API - get rest API & webhook application docking information
Shell pass parameters
成为IEEE学生会员
Opencv get (propid) common values
[explain the difference between operation and maintenance and network engineering]
Promise的使用场景
ZUCC_ Principles of compiling language and compilation_ Experiment 03 getting started with compiler
JS merge multiple objects and remove duplicates
一文详解|增长那些事儿
RCNN、Fast-RCNN、Faster-RCNN介绍
12-- merge two ordered linked lists
Qt导出PDF文件的两种方法
Shell basic operator -- arithmetic operator
Review SGI STL secondary space configurator (internal storage pool) | notes for personal use
Paper notes: multi label learning dm2l