首頁  >  文章  >  資料庫  >  mysql學習之資料引擎的範例程式碼分享

mysql學習之資料引擎的範例程式碼分享

黄舟
黄舟原創
2017-03-25 14:04:451046瀏覽

外掛程式儲存引擎是MySQL資料庫最重要的特徵之一,使用者可以根據應用程式的需要尋找如何儲存和索引資料、是否使用事務等。 MySQL預設支援多種儲存引擎,以適用於不同領域的資料庫應用需求,使用者可以透過選擇選擇不同的儲存引擎提供應用程式的效率,提供靈活的儲存

查看目前資料庫支援的引擎

show engines
+--------------------+---------+------------------------------+--------------+------+------------+
| Engine       | Support | Comment        | Transactions | XA  | Savepoints |
+--------------------+---------+---------------------+--------------+------+------------+
| InnoDB       | DEFAULT | Supports transactions, row-level locking, and foreign keys   | YES     | YES | YES    |
| MRG_MYISAM     | YES   | Collection of identical MyISAM tables             | NO      | NO  | NO     |
| MEMORY       | YES   | Hash based, stored in memory, useful for temporary tables   | NO      | NO  | NO     |
| BLACKHOLE     | YES   | /dev/null storage engine (anything you write to it disappears) | NO      | NO  | NO     |
| MyISAM       | YES   | MyISAM storage engine                     | NO      | NO  | NO     |
| CSV        | YES   | CSV storage engine                       | NO      | NO  | NO     |
| ARCHIVE      | YES   | Archive storage engine                     | NO      | NO  | NO     |
| PERFORMANCE_SCHEMA | YES   | Performance Schema                       | NO      | NO  | NO     |
| FEDERATED     | NO   | Federated MySQL storage engine                 | NULL     | NULL | NULL    |
+--------------------+---------+--------------+--------------+------+------------+
9 rows in set (0.00 sec)

show engines \G
mysql> show engines \G
*************************** 1. row ***************************
   Engine: InnoDB
   Support: DEFAULT
   Comment: Supports transactions, row-level locking, and foreign keys
Transactions: YES
     XA: YES
 Savepoints: YES
*************************** 2. row ***************************
   Engine: MRG_MYISAM
   Support: YES
   Comment: Collection of identical MyISAM tables
Transactions: NO
     XA: NO
 Savepoints: NO
*************************** 3. row ***************************
   Engine: MEMORY
   Support: YES
   Comment: Hash based, stored in memory, useful for temporary tables
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: MyISAM
   Support: YES
   Comment: MyISAM storage engine
Transactions: NO
     XA: NO
 Savepoints: NO
*************************** 6. row ***************************
   Engine: CSV
   Support: YES
   Comment: CSV storage engine
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: PERFORMANCE_SCHEMA
   Support: YES
   Comment: Performance Schema
Transactions: NO
     XA: NO
 Savepoints: NO
*************************** 9. row ***************************
   Engine: FEDERATED
   Support: NO
   Comment: Federated MySQL storage engine
Transactions: NULL
     XA: NULL
 Savepoints: NULL
9 rows in set (0.00 sec)

Engine 引擎的名稱
Support 是否支付YES表示支持,NO表示不支持
Comment 評價或備註Defalut表示,預設支援的引擎
Transactions 是否支持事務,YES表示支持,NO表示不支持
XA 所有支持的分佈式是否符合XA規範,YES表示支持,NO表示不支持
Savepoints 是否支持事務處理中的保存點,YES表示支持, NO表示不支援


show variables like 'have%'

mysql> show variables like 'have%';
+------------------------+----------+
| Variable_name     | Value  |
+------------------------+----------+
| have_compress     | YES   |
| have_crypt       | NO    |
| have_dynamic_loading  | YES   |
| have_geometry     | YES   |
| have_openssl      | DISABLED |
| have_profiling     | YES   |
| have_query_cache    | YES   |
| have_rtree_keys    | YES   |
| have_ssl        | DISABLED |
| have_statement_timeout | YES   |
| have_symlink      | YES   |
+------------------------+----------+
11 rows in set, 1 warning (0.00 sec)

Variable_name 引擎名稱
value是否支援YES支持,NO不支援,DISABLED表示支援但未啟用

查看預設引擎

show variables like '%storage_engine%'

mysql> show variables like '%storage_engine%';
+----------------------------------+--------+
| Variable_name          | Value |
+----------------------------------+--------+
| default_storage_engine      | InnoDB |
| default_tmp_storage_engine    | InnoDB |
| disabled_storage_engines     |    |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+
4 rows in set, 1 warning (0.00 sec)

InnoDB 為預設引擎

修改預設引擎

my.ini檔案

[mysqld]
# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking
# enable-named-pipe
# shared-memory
# shared-memory-base-name=MYSQL
# The Pipe the MySQL Server will use
# socket=MYSQL
# The TCP/IP Port the MySQL Server will listen on 默认端口号
port=3306
# Path to installation directory. All paths are usually resolved relative to this. 服务器的默认安装目录
# basedir="C:/Program Files/MySQL/MySQL Server 5.7/"
# Path to the database root  数据库数据文件的目录
datadir=C:/ProgramData/MySQL/MySQL Server 5.7\Data
# The default character set that will be used when a new schema or table is
# created and no character set is defined 修改服务器默认字符
character-set-server=utf8
# The default storage engine that will be used when create new tables when
# 这里修改默认引擎
default-storage-engine=INNODB

修改後重新啟動Mysql服務

以上是mysql學習之資料引擎的範例程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn