mysql中的varchar(100)声明使用多少实际存储空间? [英] How much real storage is used with a varchar(100) declaration in mysql?

查看:1901
本文介绍了mysql中的varchar(100)声明使用多少实际存储空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个表,该表的字段声明为接受varchar(100),然后我实际上插入单词"hello",那么在mysql服务器上将使用多少实际存储空间?即使声明了varchar(100),插入NULL也会导致不使用任何存储空间吗?

If I have a table with a field which is declared as accepting varchar(100) and then I actually insert the word "hello" how much real storage will be used on the mysql server? Also will an insert of NULL result in no storage being used even though varchar(100) is declared?

答案是什么,在不同的数据库实现中是否一致?

What ever the answer is, is it consistent accross different database implementations?

推荐答案

如果我有一个表,其中的字段 被声明为接受varchar(100) 然后我实际上插入一个词 你好"实际存储空间将是多少 在mysql服务器上使用?

If I have a table with a field which is declared as accepting varchar(100) and then I actually insert the word "hello" how much real storage will be used on the mysql server?

Mysql将存储5个字节,再加上一个字节作为长度.如果varchar大于255,则它将存储2个字节的长度.

Mysql will store 5 bytes plus one byte for the length. If the varchar is greater than 255, then it will store 2 bytes for the length.

请注意,这取决于列的字符集.如果字符集是utf8,则mysql每个字符最多需要3个字节.某些存储引擎(例如内存)将始终要求字符集每个字符的最大字节长度.

Note that this is dependent on the charset of the column. If the charset is utf8, mysql will require up to 3 bytes per character. Some storage engines (i.e. memory) will always require the maximum byte length per character for the character set.

也会在其中插入NULL 即使没有使用存储空间 是否声明了varchar(100)?

Also will an insert of NULL result in no storage being used even though varchar(100) is declared?

使列可为空意味着mysql将不得不为每行最多8个可为空的列留出一个额外的字节.这就是所谓的空掩码".

Making a column nullable means that mysql will have to set aside an extra byte per up to 8 nullable columns per row. This is called the "null mask".

答案是什么,在不同的数据库实现中是否一致?

What ever the answer is, is it consistent accross different database implementations?

这甚至在mysql中的存储引擎之间也不一致!

It's not even consistent between storage engines within mysql!

这篇关于mysql中的varchar(100)声明使用多少实际存储空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆