时间:2023-10-30来源:系统城装机大师作者:佚名
1 2 3 4 5 6 7 8 9 10 |
mysql> CREATE TABLE food( -> id INT (10) PRIMARY KEY AUTO_INCREMENT NOT NULL , -> NAME VARCHAR (20) NOT NULL , -> company VARCHAR (30) NOT NULL , -> price FLOAT , -> produce_time YEAR , -> validity_time INT (4), -> address VARCHAR (50) -> ); Query OK, 0 rows affected (0.07 sec) |
1 2 |
mysql> INSERT INTO food(id, NAME ,company,price,produce_time,validity_time,address) VALUES (4, 'FF咖啡' , 'FF咖啡厂' ,20,2002,5, '天津' ); ERROR 1366 (HY000): Incorrect string value: '\xE5\x92\x96\xE5\x95\xA1' for column 'NAME' at row 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
mysql> show variables like '%char%' ; + --------------------------------------+----------------------------+ | Variable_name | Value | + --------------------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | | validate_password_special_char_count | 1 | + --------------------------------------+----------------------------+ 9 rows in set (0.00 sec) |
1 2 3 4 |
mysql> set character_set_database=utf8; Query OK, 0 rows affected, 1 warning (0.02 sec) mysql> set character_set_server=utf8; Query OK, 0 rows affected (0.00 sec) |
1 2 3 |
drop database student; create database student; use student; |
建表、添加数据
1 2 3 4 5 6 7 |
mysql> create table Student( -> Sno int not null auto_increment primary key , -> Sname varchar (10) not null , -> Sex char (1) not null , -> Sage tinyint(100) not null , -> Sdept char (4) not null )comment = '学生表' ; Query OK, 0 rows affected (0.03 sec) |
1 2 |
mysql> insert into Student values ( 1, '李勇' , '男' , 20, 'CS' ); Query OK, 1 row affected (0.02 sec) |
ok,成功解决
如果某表中需要添加中文字符时需要在其库之前将character_set_database和character_set_server
设置为utf8
1 2 |
set character_set_database=utf8; set character_set_server=utf8; |
然后再建库,建表插入中文字符数据
到此这篇关于关于Mysql插入中文字符报错ERROR 1366(HY000)的解决方法的文章就介绍到这了
2023-10-30
windows上的mysql服务突然消失提示10061 Unkonwn error问题及解决方案2023-10-30
MySQL非常重要的日志bin log详解2023-10-30
详解MySQL事务日志redo log一、单表查询 1、排序 2、聚合函数 3、分组 4、limit 二、SQL约束 1、主键约束 2、非空约束 3、唯一约束 4、外键约束 5、默认值 三、多表查询 1、内连接 1)隐式内连接: 2)显式内连接: 2、外连接 1)左外连接 2)右外连接 四...
2023-10-30
Mysql删除表重复数据 表里存在唯一主键 没有主键时删除重复数据 Mysql删除表中重复数据并保留一条 准备一张表 用的是mysql8 大家自行更改 创建表并添加四条相同的数据...
2023-10-30