varchar(20):20指的是表中的a字段能存储的最大字符个数

In contrast to CHARVARCHAR values are stored as a 1-byte or 2-byte length prefix plus data.

The length prefix indicates the number of bytes in the value.

A column uses one length byte if values require no more than 255 bytes,

two length bytes if values may require more than 255 bytes.

mysql> create table t1( a varchar());
Query OK, rows affected (0.27 sec)
mysql> show create table t1;
+-------+---------------------------------------------------------------
| Table | Create Table
+-------+---------------------------------------------------------------
| t1 | CREATE TABLE `t1` (
`a` varchar() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------
row in set (0.00 sec)
mysql> insert into t1 select repeat("a",);
ERROR (): Data too long for column 'a' at row
mysql> insert into t1 select repeat("a",);
Query OK, row affected (0.09 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select repeat("我",);
ERROR (): Data too long for column 'a' at row
mysql> insert into t1 select repeat("我",);
Query OK, row affected (0.11 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select "我我我我我我我我我我我我我我我我我我我1";
Query OK, row affected (0.09 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select "我我我我我我我我我我我我我我我我我我我11";
ERROR (): Data too long for column 'a' at row

varchar 存储极限:

表为utf8字符集:

mysql> show create table a;
+-------+-------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------+
| a | CREATE TABLE `a` (
`a` varchar() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------+
row in set (0.01 sec)
mysql> create table a( a varchar());
ERROR (): Column length too big for column 'a' (max = ); use BLOB or TEXT instead
mysql> create table a( a varchar());
ERROR (): Column length too big for column 'a' (max = ); use BLOB or TEXT instead
mysql> create table a( a varchar());
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs, is . This includes st
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a( a varchar());
Query OK, rows affected (0.31 sec)

表为latin1字符集:

mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
Query OK, rows affected (0.33 sec)

不能插入汉字:

mysql> insert into a1 select repeat("我",);
ERROR (HY000): Incorrect string value: '\xE6\x88\x91\xE6\x88\x91...' for column 'a' at row
mysql> insert into a1 select "我";
ERROR (HY000): Incorrect string value: '\xE6\x88\x91' for column 'a' at row 1 mysql> insert into a1 select repeat("a",);
Query OK, row affected (0.17 sec)
Records: Duplicates: Warnings:

最新文章

  1. java工作流软件发送邮件的方案
  2. javaWeb开发小工具---MailUtils及其单元测试
  3. Mac系统下,在android studio中使用Github版本管理
  4. 测试相关、sdk卡读取
  5. java 非法字符过滤 , 半角/全角替换
  6. ERROR hdfs.DFSClient: Failed to close file解决方法
  7. [CSS]float&clear浮动
  8. php 判断数组相等 数组运算符介绍
  9. javascript 实现分享功能
  10. javaDay1 基础知识
  11. javascript的null 和undifined
  12. react 体验 react与vue的比较
  13. 2017CCPC 网络选拔赛1003 Ramsey定理
  14. spring cloud分布式配置中心案例
  15. 对象及变量的并发访问(同步方法、同步代码块、对class进行加锁、线程死锁)&内部类的基本用法
  16. System.ServiceModel.CommunicationException: 接收HTTP 响应时错误发生
  17. solr学习
  18. 用户人品预测大赛--TNT_000队--竞赛分享
  19. linux c 检测ip变化
  20. English trip -- Review Unit1 Personal Information 个人信息

热门文章

  1. 02-Vue入门之数据绑定
  2. Linux:软件安装
  3. 西安.NET俱乐部群 推广代码
  4. 通过weburl 启动windows程序
  5. nginx 配置其他路径
  6. C++与C#的时间转换
  7. django文件上传下载
  8. arcgis打开图层后右下角坐标小数点位数调整
  9. 一个3D的多人在线游戏, 服务端 + 客户端 【转】
  10. Qt txt文本中获取字符串的问题