數據庫(三):存儲引擎


進擊のpython

*****

數據庫——存儲引擎


上一節在表的操作的最后一點,提到了一個設置存儲引擎

那什么是存儲引擎呢?存儲引擎能用來干什么?

這就是本小節所要研究的問題了


存儲引擎

庫就是創建了一個文件夾,在文件夾里存儲的文件就叫表

那根據生活常識應該知道,不同的文件的格式是不一樣的

文字的就是txt,視頻的就是MP4,音樂的就是MP3... ...

那對於表來說也應該有不同的類型用以存儲不同的信息

那這個搜索引擎,就是表的類型


MySQL支持的引擎

有個語句可以幫助你知道有什么引擎

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: MRG_MYISAM
     Support: YES
     Comment: Collection of identical MyISAM tables
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 3. row ***************************
      Engine: MyISAM
     Support: YES
     Comment: MyISAM storage engine
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 4. row ***************************
      Engine: BLACKHOLE
     Support: YES
     Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 5. row ***************************
      Engine: CSV
     Support: YES
     Comment: CSV storage engine
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 6. row ***************************
      Engine: MEMORY
     Support: YES
     Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 7. row ***************************
      Engine: ARCHIVE
     Support: YES
     Comment: Archive storage engine
Transactions: NO
          XA: NO
  Savepoints: NO
*************************** 8. row ***************************
      Engine: InnoDB
     Support: DEFAULT
     Comment: Supports transactions, row-level locking, and foreign keys
Transactions: YES
          XA: YES
  Savepoints: YES
*************************** 9. row ***************************
      Engine: PERFORMANCE_SCHEMA
     Support: YES
     Comment: Performance Schema
Transactions: NO
          XA: NO
  Savepoints: NO
9 rows in set (0.00 sec)

那現在就進行簡單的介紹,只是了解!!!!!!

create table e1(id int) engine= innodb;

create table e2(id int) engine= memory;

create table e3(id int) engine= blackhole;

create table e4(id int) engine= myisam;

mysql> create table e1(id int) engine= innodb;
Query OK, 0 rows affected (0.72 sec)

mysql>
mysql> create table e2(id int) engine= memory;
Query OK, 0 rows affected (0.07 sec)

mysql>
mysql> create table e3(id int) engine= blackhole;
Query OK, 0 rows affected (0.13 sec)

mysql>
mysql> create table e4(id int) engine= myisam;
Query OK, 0 rows affected (0.14 sec)

mysql> show tables;
+-------------+
| Tables_in_e |
+-------------+
| e1          |
| e2          |
| e3          |
| e4          |
+-------------+
4 rows in set (0.00 sec)

創建了之后,我們就去文件夾里找一下我們剛才創建的文件

frm后綴的是表結構,ibd 就是 innodb的縮寫,所以我們就看出來不是一個表就對應一個文件,那只是你的意淫

e2的搜索引擎是memory,特點是存在內存里的,而不是硬盤,所以沒有數據存儲,只有表結構

e3的搜索引擎是blackhole,特點是放進去數據就沒了,所以也不需要數據存儲,只有表結構

e4的搜索引擎是myisam,特點是支持索引,所以除了表結構,數據以外,還多了個索引文件

還是這句話,只是簡單了解就行!

那現在就來試試每個引擎下的表的特點


引擎實例展示

首先先給上面的表格賦值

insert into e1 values(1);

insert into e2 values(1);

insert into e3 values(1);

insert into e4 values(1);

只驗證兩個具有代表性的引擎:

blackhole

mysql>  select * from e1;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql>
mysql>  select * from e2;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.02 sec)

mysql>
mysql>  select * from e3;
Empty set (0.00 sec)

mysql>
mysql>  select * from e4;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

我們可以看出來e3里面的數據不見了,所以是不是丟進去就沒有了~

memory

這是將數據放在內存中,也就是將內存清理后數據就不見了

那怎么辦才是將內存進行清理呢?關掉服務再開啟就ok了

C:\Users\Administrator>net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止。


C:\Users\Administrator>net start mysql
MySQL 服務正在啟動 ...
MySQL 服務已經啟動成功。


C:\Users\Administrator>mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.45 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use e
Database changed
mysql> select * from e1;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.08 sec)

mysql> select * from e2;
Empty set (0.03 sec)

mysql> select * from e3;
Empty set (0.03 sec)

mysql> select * from e4;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.03 sec)

所以說可以確定memory引擎是將表存在內存的


*****
*****


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM