mysql 占用的内存大小
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 占用的内存大小的更多相关文章
- python 计算apache进程占用的内存大小以及占物理内存的比例
目的:计算所有apache进程占用的内存大小以及占物理内存的比例: 思路:利用系统中/proc/meminfo的现有数据进行统计 1.pidof列出服务对应进程的PID [root@yanglih ...
- android 获取Bitmap位图所占用的内存大小
今天在看Universal-Image-Loader源码的时候,在对图片的超过用户在所设的阈值的时候,系统会调用GC将LinkHashMap比较靠底层的图片引用去掉,这里涉及到一个技术单个图片的文图大 ...
- Java程序占用实际内存大小
很多人错误的认为运行Java程序时使用-Xmx和-Xms参数指定的就是程序将会占用的内存,但是这实际上只是Java堆对象将会占用的内存.堆只是影响Java程序占用内存数量的一个因素.要更好的理解你的J ...
- 获取JAVA对象占用的内存大小
介绍两种获取JAVA对象内存大小的方法. 第一种:Instrumentation 简介: 使用java.lang.instrument 的Instrumentation来获取一个对象的内存大小.利用I ...
- 通过修改my.ini配置文件来解决MySQL 5.6 内存占用过高的问题
打开后台进程发现mysql占用的内存达到400+M. 修改一下my.ini这个配置文件的配置选项是可以限制MySQL5.6内存占用过高这一问题的,具体修改选项如下: performance_schem ...
- 查看redis占用内存大小的方法
查看redis占用内存大小的方法 <pre>redis-cli auth 密码info</pre><pre># Memory used_memory:1349009 ...
- 如何查看redis占用内存大小
redis缓存固然高效,可是它会占用我们系统中宝贵的内存资源,特别是当我们的项目运行了一段时间后,我们需要看一下redis占用了多少内存,那么可以用“info”命令查看. 执行info命令后,找到Me ...
- Android高效内存1:一张图片占用多少内存
在做内存优化的时候,我们发现除了解决内存泄露问题,剩下的就只有想办法减少真实的内存占用.而在App中,大部分内存可能被我们图片占用了,所以减少图片的内存占用可以带来直接的效果.本文就简单介绍一张图片到 ...
- linux下查询进程占用的内存方法总结
linux下查询进程占用的内存方法总结,假设现在有一个「php-cgi」的进程 ,进程id为「25282」.现在想要查询该进程占用的内存大小.linux命令行下有很多的工具进行查看,现总结常见的几种方 ...
随机推荐
- ectouch第二讲之 文件结构
相信大家在ectouch官网都注意到了,ectouch采用的MVC框架,之前一直以为它用的和ecshop一样都是smarty,本鸟默默按照smarty的文件结构研究了好几天,结果是各种文件对不上号.无 ...
- C++ Template Operator
#include <iostream> #include <string> #include <deque> #include <stdexcept> ...
- js比typeof更准确的验证类型方法
var type = function (o){ var s = Object.prototype.toString.call(o); return s.match(/\[object (.*?)\] ...
- Asp.net 与 jsp 交互 (打开或跳转页面)
//// 打开固定大小窗体 Response.Write("<script>window.open('Tree1_edit.aspx','child','width=300,he ...
- poj3372 Candy Distribution
可以证明: f(k) = k *(k - 1)/ 2 (1 ≤ k ≤ n)是n的完全剩余系当且仅当n = 2 ^ t. http://poj.org/problem?id=3372
- Python学习笔记-Day2-Python基础之列表操作
列表的常用操作包括但不限于以下操作: 列表的索引,切片,追加,删除,切片等 这里将对列表的内置操作方法进行总结归纳,重点是以示例的方式进行展示. 使用type获取创建对象的类 type(list) 使 ...
- zend studio 注释快捷键
使用zend studio编写程序时,我们经常要做一些注释.zend studio为我们提供了行注释和块注释的快捷键ctrl+slash和ctrl+shift+slash,开始不明白什么是slash, ...
- 使用 JavaScript
我们要用 JavaScript,但是把它写在哪里呢? 这里 ↘ 1. HTML 页面中 . 2. 单独的一个文件中,文件后缀名是“.js”. ——————————————————— ...
- ADO,NET 实体类 和 数据访问类
啥也不说,看代码. --SQl中 --建立ren的数据库,插入一条信息 create database ren go use ren go create table xinxi ( code ) pr ...
- Jams倒酒(pour)
1.Jams倒酒(pour) Jams是一家酒吧的老板,他的酒吧提供2种体积的啤酒,a ml 和 b ml,分别使用容积为a ml 和 b ml的酒杯来装载. 酒吧的生意并不好.Jams发现酒鬼们都很 ...