1、mysql执行查询计划,key_len表示索引使用的字节数,这个字节数和三个条件有关。
mysql> create table t1(v1 char(10));
Query OK, 0 rows affected

mysql> create index index_v1 on t1(v1);
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

2、是否允许为null,允许为null 会多一个字节,标识取值是否为NULL。如下:
mysql> alter table t1 modify column v1 char(10) not null;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 30 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set

mysql> alter table t1 modify column v1 char(10) null;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 31 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set
3、是否为变长,变长多出两个字节表示长度,如下:
mysql> alter table t1 modify column v1 varchar(10) null;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 33 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set

mysql> alter table t1 modify column v1 char(10) null;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 31 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set
4、字符类型,varchar(n) 中的n是字符个数,不是占用多少个字节的内存。对于不同的编码,同样一个字符占用的内存不一样。latin1 一个字符占用1个字节,gb2312 一个字符占用2个字节,utf8 一个字符占用3个字节。
mysql> alter table t1 modify column v1 char(10) charset latin1;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 11 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set

mysql> alter table t1 modify column v1 char(10) charset gb2312;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 21 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set

mysql> alter table t1 modify column v1 char(10) charset utf8;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc select * from t1;
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
| 1 | SIMPLE | t1 | index | NULL | index_v1 | 31 | NULL | 1 | Using index |
+----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+
1 row in set

mysql 占用的内存大小的更多相关文章

  1. python 计算apache进程占用的内存大小以及占物理内存的比例

      目的:计算所有apache进程占用的内存大小以及占物理内存的比例: 思路:利用系统中/proc/meminfo的现有数据进行统计 1.pidof列出服务对应进程的PID [root@yanglih ...

  2. android 获取Bitmap位图所占用的内存大小

    今天在看Universal-Image-Loader源码的时候,在对图片的超过用户在所设的阈值的时候,系统会调用GC将LinkHashMap比较靠底层的图片引用去掉,这里涉及到一个技术单个图片的文图大 ...

  3. Java程序占用实际内存大小

    很多人错误的认为运行Java程序时使用-Xmx和-Xms参数指定的就是程序将会占用的内存,但是这实际上只是Java堆对象将会占用的内存.堆只是影响Java程序占用内存数量的一个因素.要更好的理解你的J ...

  4. 获取JAVA对象占用的内存大小

    介绍两种获取JAVA对象内存大小的方法. 第一种:Instrumentation 简介: 使用java.lang.instrument 的Instrumentation来获取一个对象的内存大小.利用I ...

  5. 通过修改my.ini配置文件来解决MySQL 5.6 内存占用过高的问题

    打开后台进程发现mysql占用的内存达到400+M. 修改一下my.ini这个配置文件的配置选项是可以限制MySQL5.6内存占用过高这一问题的,具体修改选项如下: performance_schem ...

  6. 查看redis占用内存大小的方法

    查看redis占用内存大小的方法 <pre>redis-cli auth 密码info</pre><pre># Memory used_memory:1349009 ...

  7. 如何查看redis占用内存大小

    redis缓存固然高效,可是它会占用我们系统中宝贵的内存资源,特别是当我们的项目运行了一段时间后,我们需要看一下redis占用了多少内存,那么可以用“info”命令查看. 执行info命令后,找到Me ...

  8. Android高效内存1:一张图片占用多少内存

    在做内存优化的时候,我们发现除了解决内存泄露问题,剩下的就只有想办法减少真实的内存占用.而在App中,大部分内存可能被我们图片占用了,所以减少图片的内存占用可以带来直接的效果.本文就简单介绍一张图片到 ...

  9. linux下查询进程占用的内存方法总结

    linux下查询进程占用的内存方法总结,假设现在有一个「php-cgi」的进程 ,进程id为「25282」.现在想要查询该进程占用的内存大小.linux命令行下有很多的工具进行查看,现总结常见的几种方 ...

随机推荐

  1. HDU 5787:K-wolf Number(数位DP)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5787 题意:要求相邻的K个位的数不能相同,在[L,R]区间有多少个这样的数. #inclu ...

  2. Asp.net Vnext ModelBinding

    Model Binding 本文已经同步到<Asp.net Vnext 系列教程 >中] Model binding(绑定)简单来说就是通过遍历ValueProvider(值提供者)获取的 ...

  3. Xcode中设置按钮在十分钟之内禁用

    btn.enabled=NO;` NSTimer * notificationTimer = [NSTimer scheduledTimerWithTimeInterval:10*60.0 targe ...

  4. Andriod 字符串数组里加入字符串元素

    private String[] t1 = { "姓名", "性别", "年龄", "居住地","邮箱&quo ...

  5. 使用repeater实现gridview的功能

    <asp:Repeater ID="rptfindData" runat="server"> <HeaderTemplate> < ...

  6. 【linux命令与工具】ethtool命令

    ethtool是用于查询及设置网卡参数的命令. 如果command not found可以用apt-get/yum添加. 主要参数: ethtool ethX//查看ethX设备属性 ethtool ...

  7. 深入Linux网络核心堆栈(对于netfilter的用法和讲解)

    http://blog.csdn.net/wswifth/article/details/5115475 注册一个hook函数是围绕nf_hook_ops数据结构的一个非常简单的操作,nf_hook_ ...

  8. 为Apache配置虚拟机Virtual Host

    配置虚拟机最少需要修改两个文件,即httpd-vhosts.conf 和 hosts (记住修改任何配置前先备份哦,这才是个好习惯) 第一步,修改httpd-vhosts.conf文件, 文件路径 \ ...

  9. 递归,动态规划,找最短路径,Help Jimmy

    题目链接:http://poj.org/problem?id=1661 解题报告: 1.老鼠每次来到一块木板上都只有两条路可以走,可以使用递归 #include <stdio.h> #in ...

  10. 基于PowerShell 3.0的web接口测试

    对于web接口测试,做一下总结. 接口测试总结 1. 接口url格式:http://www.xxx.com/a/bbb.html: 2. 接口url后面接的参数格式:“?参数名=参数值&参数名 ...