当前位置:网站首页>Mysql——》varchar
Mysql——》varchar
2022-06-10 00:58:00 【Xiao Xian.】
Recommended links :
summary ——》【Java】
summary ——》【JVM】
summary ——》【Mysql】
summary ——》【Spring】
summary ——》【SpringBoot】
Mysql——》varchar
One 、varchar Introduce
VARCHAR The value in the column is variable length character string .VARCHAR The maximum effective length of is determined by the maximum line size and the character set used .
| edition | varchar(n) | varchar(20) | Length range ( byte ) | Maximum length ( byte ) |
|---|---|---|---|---|
| MySQL 5.0.3 Before | n: Number of bytes | Maximum storage 20 Bytes utf-8 code : You can only put 6 The Chinese characters | 0-255 | 255 |
| MySQL 5.0.3 after | n: Number of characters | Maximum storage 20 Characters It has nothing to do with coding | 0-65535 | 65535: Specified maximum length 65533: When non empty fields are not allowed 65532: When non empty fields are allowed |
1、 Why? varchar The maximum length is 65535 Bytes ?
Q: Why? varchar The maximum length is 65535 Bytes ?
A: because mysql It specifies that the data size of each row cannot exceed 65535 Bytes .
2、varchar Store the length in a few bytes ?
Q:varchar Store the length in a few bytes ?
A:
Less than 255 byte , use 1 Byte storage length
Greater than 255 byte , use 2 Byte storage length
3、varchar Use a few bytes to identify whether the field is empty
Q: A field, if allowed, is null, Identify with a few bytes ?
A: use 1 Bytes
Two 、varchar Maximum character length test
varchar Maximum character length = ( Maximum bytes per row (65535) - null Number of identification bytes - Length prefix bytes (1 or 2)) / The maximum number of bytes occupied by a single character
1、 scene
Create table :test
Character set :UTF8
Field :name, Non empty , char(255)
Field :address, Non empty ,varchar(n),n Is the maximum character length we will witness
2、 Calculation
The maximum number of bytes per row of data :**65535 **
char(255) Maximum number of bytes :255*3( One character can occupy at most 3 Bytes )
varchar(n) Storage length bytes :2( exceed 255 For byte 2 Byte storage length )
The field is not empty :0( If the field allows null, You need to 1 Byte store null identification )
varchar(n) The maximum number of bytes = **65535 - **255*3 - 2 = 64768
varchar(n) The maximum number of characters = Number of bytes /3
n = 64768/3 = 21589.33
3、 test
-- n=21589.33, Table created successfully
create table test1 (name char(255) not null, address varchar(21589.33) not null );
-- n=21589.34, Table created successfully
create table test2 (name char(255) not null, address varchar(21589.34) not null );
-- n=21589, Table created successfully
create table test3 (name char(255) not null, address varchar(21589) not null );
-- n=21590, Failed to create table
create table test4 (name char(255) not null, address varchar(21590) not null );
(1)n=21589.33, Table created successfully


(2)n=21589.34, Table created successfully


(3)n=21589, Table created successfully


(4)n=21590, Failed to create table

1118 - 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
边栏推荐
- Hcip day 1 Summary
- Score of sub series of previous test questions and [11th] [provincial competition] [group B]
- Mysql——》如何解决数据的读一致性问题
- Sword finger offer II 017 The shortest string containing all characters
- Bubble sorting and optimization clear and intuitive C language
- 上位机开发——Modbus到底有多快
- 浅谈Cookie 和 Session——含案例及详细注解
- BGP总结
- 剑指 Offer II 020. 回文子字符串的个数
- 剑指 Offer II 016. 不含重复字符的最长子字符串
猜你喜欢
试题 历届真题 回文日期【第十一届】【省赛】【B组】

Interface control devaxpress WinForms -- new WXI skin grabs "fresh" view
Analysis on the scores of previous real questions [11th] [provincial competition] [group B]

剑指 Offer II 020. 回文子字符串的个数

Hcip day 1 Summary

The latest version of Alibaba development manual is released in 2022!!!

Work sharing of 2018 virtual instrument competition - reconfigurable snake shaped robot based on LabVIEW, baidu map, STM32 single chip microcomputer, etc

代码案例—— web版表白墙及文件上传

Republish experiment

gurobi解的状态及其属性获取
随机推荐
Typera basic use and change the theme style of typera
Blue Bridge Cup · winter vacation hundred schools' real topic league tournament (Phase V) real topic exercise of cargo placement for graduate students and university group A
The binary tree is expanded into a linked list [the essence of tree processing -- how to handle each sub tree]
Mysql——》事务
Pycharm 2022 permanently activated version download, valid for personal test
Internal network infiltration tunnel
if判断是否为空时的函数选择
LEAK: ByteBuf. release() was not called before it‘s garbage-collected
数据库之App.config配置文件错误
应用最新的AD和TXK补丁
WPS how to adjust the position of text after merging cells
OSPF experiment
[GoogleCTF2019 Quals]Bnv -S
Minimum toll
Node-RED系列(二三):在Node-RED中开发一个高德地图面板dashboard
Wyn enterprise, an embedded business intelligence software, has officially entered the V5.0 era!
Can the online security of futures account opening be guaranteed? Which futures company is good?
Gartner global IAAs report in 2021: AWS cake is nibbled, and Chinese cloud manufacturers are steadily attacking
xargs命令详解,xargs与管道的区别
The state of gurobi solution and its attribute acquisition