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:

VARCHAR 详解的更多相关文章

  1. MySQL数据类型varchar详解

    1.varchar(N)的逻辑意义从MySQL 4.1开始,varchar(N)中的N指的是该字段最多能存储多少个字符(characters),不是字节数.不管是一个中英文字符或者数字.或者一个汉字, ...

  2. CHAR与VARCHAR详解

    前言:  前面写过一篇介绍int类型的文章,一直想写一篇介绍字符串字段类型的文章,一直拖着也没思路要怎么下手.最近多关注了下这方面的文章,决定还是把拖了好久的文章了结了吧.本篇文章主要会介绍字符串类型 ...

  3. MySQL中的char与varchar详解

    mysql中char与varchar的区别: char:定长,效率高,一般用于固定长度的表单提交数据存储  :例如:身份证号,手机号,电话,密码等 varchar:不定长,效率偏低 1.varchar ...

  4. mysql中char和varchar详解

    一.首先创建表. CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL, `a` char(255) DEFAULT NULL) ENGINE=InnoDB DE ...

  5. [原创]mybatis详解说明

    mybatis详解 2017-01-05MyBatis之代理开发模式1 mybatis-Dao的代理开发模式 Dao:数据访问对象 原来:定义dao接口,在定义dao的实现类 dao的代理开发模式 只 ...

  6. Python中操作mysql的pymysql模块详解

    Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...

  7. MySQL 数据类型 详解

    MySQL 数据类型 详解 MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 My ...

  8. SQL注入攻防入门详解

    =============安全性篇目录============== 本文转载 毕业开始从事winfrm到今年转到 web ,在码农届已经足足混了快接近3年了,但是对安全方面的知识依旧薄弱,事实上是没机 ...

  9. SQL Server时间粒度系列----第8节位运算以及设置日历数据表节假日标志详解

    本文目录列表: 1.位运算 2.设置日历数据表节假日标志 3.总结语 4.参考清单列表   位运算   SQL Server支持的按位运算符有三个,分别为:按位与(&).按位或(|).按位异或 ...

随机推荐

  1. MySql执行多条语句

    http://www.cppblog.com/fwxjj/archive/2010/08/05/122258.html说是在连接上设置: //链接时设定 mysql_real_connect( ... ...

  2. 更新页面缓存OutputCache

    为什么要使用OutputCache 我认为OutputCache是最简单的缓存技术了,它针对的是页面级别的,简单的一条指令就可以达到缓存的效果,有效的减轻服务器的压力和减少带宽,对于网站一些不会频繁更 ...

  3. 菜鸟学习WCF笔记-概念

    背景 WCF这个词语一直不陌生,以前也使用过多次在实际的项目中,但是一直没有时间来做个系统的学习,最近抽点时间,看看 蒋金楠的<WCF全面解析>学习下,顺带做些笔记,如有错误,欢迎各路大神 ...

  4. 盘点mysql中容易被我们误会的地方

    引语:mysql作为数据库的一大主力军,到处存在于我们各种系统中,相信大家都不陌生!但是,你知道你能用不代表你知道细节,那我们就来盘点盘点其中一些我们平时不太注意的地方,一来为了有趣,二来为了不让自己 ...

  5. JavaWeb学习总结(十二)——Session

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  6. 使用jquery修改css中带有!important的样式属性

    当CSS中含有!important的样式属性时,普通的修改方式是会出现失败的.如下: <div class="test">使用jquery修改css中带有!import ...

  7. 使用Reveal查看任意App的技巧

    转:http://www.jianshu.com/p/4dc8f94ca27c 前言 Reveal(http://revealapp.com)是一个很强大的iOS View Hierarchy工具,与 ...

  8. 连接Oracle错误:800a0e7a未找到提供程序的解决

    一.现象: C#程序中需要以Provider=OraOLEDB.Oracle.1方式访问ORACLE数据库.但程序执行时报异常:未在本地计算机注册“OraOLEDB.Oracle.1”提供程序 二.解 ...

  9. 环回接口(loopback interface)的新认识

    背景 前些日子在IDC实验docker的时候,为了避免与公司网络冲突,将bridge设置为127.x网段的IP,原以为这样就OK,后来发现在访问container内部的服务的时候无法访问.开始以为ip ...

  10. mybatis中传入String类型参数异常

    在使用mybatis时,写了一条sql语句,只有一个String类型的参数, 示例代码 <select id="getApplyNum" parameterType=&quo ...