sofast 2020-04-22
• Memory存储引擎将所有数据存储在内存中以便加快对某些不重要数据的访
问速度
• 此存储引擎的使用范围已经变小,因为InnoDB已经提供了数据缓存区以便
对将经常访问的数据缓存在内存中
• 当MySQL重启时,Memory表中的数据会丢失,但表结构还在
• Memory只适用在只读表或者读操作占绝大多数的情况,因为对表的写操作
也会导致表锁,大大限制了并发性
• Memory表创建之后,在磁盘文件会生成一个相同表名的文件,后缀为.frm
,仅存储表结构而不存储表数据
[ ~]# mysql -u root -p mysql> CREATE TABLE test(id int,name varchar(10)) ENGINE=MEMORY; Query OK, 0 rows affected (0.11 sec) mysql> insert into test values(1,‘a‘); Query OK, 1 row affected (0.01 sec) mysql> insert into test values(2,‘b‘); Query OK, 1 row affected (0.01 sec) mysql> select * from temp; Empty set (0.01 sec) mysql> select * from test; +------+------+ | id | name | +------+------+ | 1 | a | | 2 | b | +------+------+ 2 rows in set (0.01 sec) mysql> exit; Bye
[ ~]# /etc/init.d/mysql.server restart Shutting down MySQL.... SUCCESS! Starting MySQL.. SUCCESS! [-master ~]# mysql -u root -p mysql> use course; Database changed mysql> select * from test; Empty set (0.00 sec) mysql> desc test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(10) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.01 sec)