MySQL 内存表的总结

The MEMORY storage engine creates tables with contents that are stored in memory.

 

Formerly, these were known as HEAP tables. MEMORY is the preferred term, although HEAP remains supported for backward compatibility.

 

Each MEMORY table is associated with one disk file. The filename begins with the table name and has an extension of .frm to indicate that it stores the table definition.

 

1、heap对所有用户的连接是可见的,这使得它非常适合做缓存。
2、仅适合使用的场合。heap不允许使用xxxTEXT和xxxBLOB数据类型;只允许使用=和<=>操作符来搜索记录(不允 许&<、>、<=或>=)。

 


内存表的建立还有一些限制条件:
MEMORY tables cannot contain BLOB or TEXT columns. HEAP不支持BLOB/TEXT列。
The server needs sufficient memory to maintain all MEMORY tables that are in use at the same time. 在同一时间需要足够的内存.

To free memory used by a MEMORY table when you no longer require its contents, you should execute DELETE or TRUNCATE TABLE, or remove the table altogether using DROP TABLE.为了释放内存,你应该执行DELETE FROM heap_table或DROP TABLE heap_table。
另外如何创建内存表?
    创建内存表非常的简单,只需注明 ENGINE= MEMORY 即可:

注意:
    当内存表中的数据大于max_heap_table_size设定的容量大小时,mysql会转换超出的数据存储到磁盘上,因此这是性能就大打折扣了,所 以我们还需要根据我们的实际情况调整max_heap_table_size,

例如在.cnf文件中[mysqld]的下面加入:
        max_heap_table_size = 2048M

另外在建表语句中还可以通过MAX_ROWS来控制表的记录数。
CREATE TABLE `tablename` ( `columnName` varchar(256) NOT NUL) ENGINE=MEMORY DEFAULT CHARSET=utf-8 MAX_ROWS=100000000;
或 写成 TYPE=HEAP MAX_ROWS=100000000; 效果是一样的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值