存储引擎是MySQL中特有的一个术语,其它数据库里没有。(oracle里有,不叫此名)
实际上存储是一个表存储/组织数据的方式。
不同的存储引擎,表存储数据的方式不同。
查看一张表的组成结构:
show create table 表名;
比如查看t_student这张表:
| t_student | CREATE TABLE `t_student` ( `no` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `cno` int(11) DEFAULT NULL, PRIMARY KEY (`no`), KEY `cno` (`cno`), CONSTRAINT `t_student_ibfk_1` FOREIGN KEY (`cno`) REFERENCES `t_class` (`classno`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 |
在建表时,可以在最后小括号的后面使用:
结论:
现在我们来建一个表,在建表时指定存储引擎及字符编码格式:
create table t_test( id int primary key, name varchar(255) ) engine = InnoDB default charset = gbk;
查看表:
| t_test | CREATE TABLE `t_test` ( `id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gbk |
我的mysql版本是:
mysql> select version(); +-----------+ | version() | +-----------+ | 5.5.62 | +-----------+
查看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
mysql支持九大存储引擎,我的版本5.5.62支持8个,版本不同支持情况也不同。
MySQL常用的存储引擎有:
提示:对于一张表来说,只要是主键,或者加有unique约束的字段上会自动创建索引。