Mysql的存储引擎有InnoDB,MyISAM,Memory,CSV,BlackHole,Archive,其中最常用的是InnoDB,MyISAM,Memory,下面将粗略介绍这几种常用存储引擎。
1、InnoDB
Mysql5.1之后,开始支持InnoDB.
Mysql5.5之后后,默认的存储引擎是InnoDB。
InnoDB支持事务和行级锁,支持热备份,支持主键索引和唯一索引,但不支持全文索引。
InnoDB实现了四个标准的隔离级别,其默认级别是REPEATABLE READ(可重复读)。
应优先选择InnoDB作为存储引擎,公司现在使用的存储引擎基本上为InnoDB。
2、MyISAM
Mysql5.1及以前的版本,默认的存储引擎都是MyISAM.
MyISAM提供了大量的特性,包括全文索引、压缩、空间函数等。但MyISAM不支持事务和行级锁,而且不支持崩溃后的安全恢复,因此MyISAM通常不是最佳选择。
3、Memory
所有数据都保存在内存中,访问速度比较快,但在重启后会丢失所有数据。Memory表是表级锁,并发写入的性能较低。
不支持BLOB或TEXT类型的列,并且每行的长度是固定的,浪费部分内存。
MySQL在执行查询的过程中需要使用临时表来保存中间结果,内部使用的临时表就是Memory表。
如果中间表结果太大超出了Memory表的限制,或者含有BLOB或TEXT字段,则临时表会转换成MyISAM表。
与本文相关的Mysql命令
1、Windows启动Mysql
命令行输入以下命令:
net start mysql
2、Windows登陆Mysql
命令行输入以下命令:
-u后面是用户名,-p后面是密码
mysql -uroot -proot
3、查Mysql版本
mysql> status; -------------- D:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe Ver 14.14 Distrib 5.5.10, for Win32 (x86) Connection id: 4 Current database: test Current user: root@localhost SSL: Not in use Using delimiter: ; Server version: 5.5.10-log MySQL Community Server (GPL) Protocol version: 10 Connection: localhost via TCP/IP Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3306 Uptime: 1 hour 36 min 49 sec Threads: 3 Questions: 38 Slow queries: 0 Opens: 40 Flush tables: 1 Open tables: 0 Queries per second avg: 0.6
4、查Mysql支持的存储引擎
mysql> show engines; +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | Engine | Support | Comment | Transactions | XA | Savepoints | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL | | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO | | MyISAM | YES | MyISAM storage engine | 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 | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | ARCHIVE | YES | Archive storage engine | NO | NO | NO | | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES | | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO | +--------------------+---------+----------------------------------------------------------------+--------------+------+------------+ 9 rows in set (0.00 sec)
5、查表使用的存储引擎
mysql> show create table student; CREATE TABLE `student` ( `student_id` bigint(20) NOT NULL AUTO_INCREMENT, `name` varchar(32) COLLATE utf8_bin DEFAULT NULL, `sex` varchar(10) COLLATE utf8_bin DEFAULT NULL, `age` int(11) DEFAULT NULL, `birth_day` date DEFAULT NULL, `name_index` varchar(32) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`student_id`), KEY `student_name_index` (`name_index`(10)) ) ENGINE=InnoDB AUTO_INCREMENT=1345038 DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
也可以通过以下命令查询,有些字段被我删减。
mysql> show table status like 'student'; Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Index_length | Data_free | Auto_increment student | InnoDB | 10 | Compact | 1023687 | 113 | 116064256 | 40992768 | 79691776 | 1345038