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. StarUML建模软件

    这星期本人进行了UML建模语言的初步学习,简单地将上学期所建立的数据库模型在该软件中实现了出来.

  2. 使用FEST-Swing测试GUI

          在Java中最常用的单元测试工具要算JUnit了.FEST-Swing是一个能够与JUnit集成的GUI测试框架.使用FEST-Swing可以更方便的对Swing进行一系列的测试.下面就说 ...

  3. [stm32] Systick

    (一) 背景介绍在传统的嵌入式系统软件按中通常实现 Delay(N) 函数的方法为:for(i=0;i<=x;i++); x--:            对应于N毫秒的循环值对于STM32系列微 ...

  4. C语言实现二叉树-利用二叉树统计单词数目

    昨天刚参加了腾讯2015年在线模拟考: 四道大题的第一题就是单词统计程序的设计思想: 为了记住这一天,我打算今天通过代码实现一下: 我将用到的核心数据结构是二叉树: (要是想了解简单二叉树的实现,可以 ...

  5. php中的邮件技术

    前言:程序员不谈恋爱就是对物质世界太贪恋 一.通过smtp服务来发送邮件 使用php中的mail()实现邮件的发送; bool mail ( string $to , string $subject ...

  6. Django基础——Model篇(一)

    到目前为止,当程序涉及到数据库相关操作时,我们一般都会这么操作:    (1)创建数据库,设计表结构和字段    (2)使用MySQLdb来连接数据库,并编写数据访问层代码    (3)业务逻辑层去调 ...

  7. Leetcode 168 Excel Sheet Column Title 进制数转化

    题意:将数字转化成excel表中的行中的项目 本质是10进制转化为26进制,但是在中间加入了一个不一样的操作,在每次操作前都需要n-- class Solution { public: string ...

  8. 如何关闭Linux里边的selinux ?

    原文地址: http://jingyan.baidu.com/article/6d704a131ba67828da51ca73.html 有很多的Linux使用者因为对selinux不熟悉,所以都会将 ...

  9. XCode升级导致的IAP失败的问题

    应用提交苹果测试之前,一般都会在沙盒环境里进行测试充值.用沙盒的测试帐号进行充值的时候,服务端拿到苹果返回的receipt-data后,向苹果服务端进行校验的时候,如果返回错误码21007则再去沙盒环 ...

  10. chrome诡异的Provisional headers are shown

    昨天吐槽了cocos2d-js的问题,所以就准备调研几个其它HTML5引擎,发现PIXI性能极高,但是没有音频.而Phaser.js是在PIXI.js的基础之上进行的封装.而国内有一家公司,开发一个叫 ...