Memory表大小受max_heap_table_size控制。
mysql> show variables like ‘max_heap_table%’;
+———————+———-+
| Variable_name | Value |
+———————+———-+
| max_heap_table_size | 16777216 |
+———————+———-+
1 row in set (0.00 sec)
测试:
mysql> set max_heap_table_size = 1024;
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> show variables like ‘max_heap_table%’;
+———————+——-+
| Variable_name | Value |
+———————+——-+
| max_heap_table_size | 16384 | –这里看来,最小只能是16384
+———————+——-+
1 row in set (0.00 sec)
1、创建memory类型的表
mysql> create table test_memory engine=memory select * from test_last_insert_id where 1=0;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
2、查询表大小
mysql> SELECT count(*) TABLES,
-> sum(table_rows) rows,
-> sum(data_length) DATA,
-> sum(index_length) idx,
-> sum(data_length+index_length) total_size,
-> round(sum(index_length)/sum(data_length),2) idxfrac
-> FROM information_schema.TABLES
-> WHERE table_name LIKE “%test_memory%”;
+——–+——+——+——+————+———+
| TABLES | rows | DATA | idx | total_size | idxfrac |
+——–+——+——+——+————+———+
| 1 | 0 | 0 | 0 | 0 | NULL |
+——–+——+——+——+————+———+1 row in set (0.00 sec)
3、调用存储过程
mysql> delimiter $$
mysql> create procedure sp_insert_memory()
-> modifies sql data
-> begin
-> set @x = 0;
-> ins: loop
-> set @x = @x + 1;
-> if @x = 10000000 then
-> leave ins;
-> end if;
-> insert into test_memory values(1,’aaaaaaaaaa’);
-> end loop ins;
-> end;
-> $$
Query OK, 0 rows affected (0.00 sec)mysql> select * from test_memory;
Empty set (0.00 sec)mysql> call sp_insert_memory();
ERROR 1114 (HY000): The table ‘test_memory’ is full
mysql> SELECT count(*) TABLES,
-> sum(table_rows) rows,
-> sum(data_length) DATA,
-> sum(index_length) idx,
-> sum(data_length+index_length) total_size,
-> round(sum(index_length)/sum(data_length),2) idxfrac
-> FROM information_schema.TABLES
-> WHERE table_name LIKE “%test_memory%”;
+——–+——+——-+——+————+———+
| TABLES | rows | DATA | idx | total_size | idxfrac |
+——–+——+——-+——+————+———+
| 1 | 816 | 16640 | 0 | 16640 | 0.00 |
+——–+——+——-+——+————+———+
1 row in set (0.00 sec)
总结:memory类型的表大小受max_heap_table_size参数控制
表大小查询sql:
http://www.mysqlperformanceblog.com/2008/03/17/researching-your-mysql-table-sizes/
Pingback: sql wildcard,sql wildcards,sql rollback,rollback sql,sql copy table,sql sum,sql mirroring,sum sql,sql cluster,sql server performance,truncate in sql,backup sql,backup sql database,backup sql server,sql performance,date functions in sql,sql over,truncate s
Pingback: Memory存储引擎表大小限制 | 阿龙的博客