当前位置:数据库 > 数据库管理> 正文

mysql字符类型长度限制

时间:2016-4-27类别:数据库

mysql字符类型长度限制

mysql字符类型长度限制

一、CHAR

 

1、char (M)

2、长度是M*字符编码长度,M最大255

  •  
  • 
    mysql> create table t1(name char(256)) default charset=utf8;
    
    --ERROR 1074 (42000): Column length too big for column 'name' (max = 255); use BLOB or TEXT instead
    
    
    mysql> create table t1(name char(255)) default charset=utf8;
    
    --Query OK, 0 rows affected (0.06 sec)
    
    
    		
  •  

     

    二、VARCHAR

     

    1、VARCHAR(M)

    2、长度是M*字符编码长度

    3、字符集是 utf8 时,最多只能指定21844的长度

  •  
  • 
    mysql> create table t1(name varchar(65532)) default charset=utf8;
    
    --ERROR 1074 (42000): Column length too big for column 'name' (max = 21845); use BLOB or TEXT instead
    
    
    mysql> create table t1(name varchar(21845)) default charset=utf8;
    
    --ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
    
    
    mysql> create table t1(name varchar(21844)) default charset=utf8;
    
    --Query OK, 0 rows affected (0.07 sec)
    
    		
  •  

    4、字符集是 latin1 时,最多只能指定65532的长度

  •  
  • 
    mysql> create table t1(name varchar(65535));
    
    --ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
    
    
    mysql> create table t1(name varchar(65534));
    
    --ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
    
    
    mysql> create table t1(name varchar(65533));
    
    --ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
    
    
    mysql> create table t1(name varchar(65532));
    
    --Query OK, 0 rows affected (0.08 sec)
    
    		
  •  

    标签:
    上一篇下一篇

    猜您喜欢

    热门推荐