前言
2022/7/30 19:19
暑假学习ing
推荐
【MySQL数据库教程天花板,mysql安装到mysql高级,强!硬!-哔哩哔哩】
第05章 存储引擎
为了管理方便,把连接管理、 查询缓存 、语法解析 、查询优化这些并不涉及真实数据存储的功能划分为MySQL server的功能,把真实存取数据的功能划分为存储引擎的功能。所以在MySQL server完成了查询优化后,只需按照生成的执行计划调用底层存储引擎提供的API,获取到数据后返回给客户端就好了。
MySQL中提到了存储引擎的概念。简而言之, 存储引擎就是指表的类型 。其实存储引擎以前叫做 表处理器 ,后来改名为 存储引擎 ,它的功能就是接收上层传下来的指令,然后对表中的数据进行提取或写入操作。
1. 查看存储引擎
- 查看mysql提供什么存储引擎:
#MySQL8.0 show engines;
/*输出: +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | NO | NO | NO | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO | | CSV | YES | CSV storage engine | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ */
查询结果显示,MySQL8.0支持9种存储引擎,分别为MEMORY、MRG_MYISAM、CSV、FEDERATED 、PERFORMANCE_SCHEMA、MyISAM、InnoDB、BLACKHOLE和ARCHIVE。
Engine参数表示存储引擎名称。
Support参数表示MySQL数据库管理系统是否支持该存储引擎:YES表示支持,NO表示不支持。DEFAULT表示系统默认支持的存储引擎。
Comment参数表示对存储引擎的评论。 Transactions参数表示存储引擎是否支持事务:YES表示支持,NO表示不支持。
XA参数表示存储引擎所支持的分布式是否符合XA规范: YES表示支持,NO表示不支持。代表着该存储引擎是否支持分布式事务。
Savepoints参数表示存储引擎是否支持事务处理的保存点:YES表示支持,NO表示不支持。也就是说,该存储引擎是否支持部分事务回滚。
show engines \G;
显示如下:
mysql> show engines \G; *************************** 1. row *************************** Engine: FEDERATED Support: NO Comment: Federated MySQL storage engine Transactions: NULL XA: NULL Savepoints: NULL *************************** 2. row *************************** Engine: MEMORY Support: YES Comment: Hash based, stored in memory, useful for temporary tables Transactions: NO XA: NO Savepoints: NO *************************** 3. row *************************** Engine: InnoDB Support: DEFAULT Comment: Supports transactions, row-level locking, and foreign keys Transactions: YES XA: YES Savepoints: YES *************************** 4. row *************************** Engine: PERFORMANCE_SCHEMA Support: YES Comment: Performance Schema Transactions: NO XA: NO Savepoints: NO *************************** 5. row *************************** Engine: MyISAM Support: YES Comment: MyISAM storage engine Transactions: NO XA: NO Savepoints: NO *************************** 6. row *************************** Engine: MRG_MYISAM Support: YES Comment: Collection of identical MyISAM tables Transactions: NO XA: NO Savepoints: NO *************************** 7. row *************************** Engine: BLACKHOLE Support: YES Comment: /dev/null storage engine (anything you write to it disappears) Transactions: NO XA: NO Savepoints: NO *************************** 8. row *************************** Engine: CSV Support: YES Comment: CSV storage engine Transactions: NO XA: NO Savepoints: NO *************************** 9. row *************************** Engine: ARCHIVE Support: YES Comment: Archive storage engine Transactions: NO XA: NO Savepoints: NO 9 rows in set (0.01 sec) ERROR: No query specified mysql>
2. 设置系统默认的存储引擎
查看默认的存储引擎:
show variables like '%storage_engine%'; # 或 SELECT @@default_storage_engine;
测试
- 修改默认的存储引擎
如果在创建表的语句中没有显式指定表的存储引擎的话,那就会默认使用 InnoDB
作为表的存储引擎。如果我们想改变表的默认存储引擎的话,可以这样写启动服务器的命令行:
#修改存储引擎(临时的) SET DEFAULT_STORAGE_ENGINE=MyISAM;
或者修改 my.cnf 文件(持久的):
default-storage-engine=MyISAM # 重启服务 systemctl restart mysqld.service
接着:
mysql> CREATE TABLE emp3(id INT); Query 0K,0 rows affected (e.82 sec)
这个定义语句中我们并没有明确指定表的存储引擎,创建成功后再看一下这个表的结构:
接下来,我们去到存储的数据目录中:
cd /var/lib/mysql ll cd ./dbtest1; ll