1.存储引擎
查看MySQL提供了哪些存储引擎
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| CSV | YES | CSV 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 |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| 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)
查看MySQL当前默认的存储引擎
mysql> show variables like '%storage_engine%';
+----------------------------+--------+
| Variable_name | Value |
+----------------------------+--------+
| default_storage_engine | InnoDB |
| default_tmp_storage_engine | InnoDB |
| storage_engine(当前存储引擎) | InnoDB |
+----------------------------+--------+
3 rows in set (0.00 sec)
对比项 |
MyISAM
|
InnoDB
|
外键 | 不支持 | 支持 |
事务 | 不支持 | 支持 |
行表锁 |
表锁,即使操作一条记录也会锁住整张表, 不适合高并发的操作 |
行锁,操作时只锁定某一行,不对其他的行有影响, 适合高并发的操作 |
缓存 | 只缓存索引,不缓存真实数据 |
不仅缓存索引还缓存真实数据,对内存要求较高, 而且内存大小对性能有决定性影响 |
表空间 | 小 | 大 |
关注点 | 性能 | 事务 |
2.sql性能下降的原因
1).查询语句写的烂。
2).索引失效,可能常用的搜索字段没有建索引。
3).关联查询太多的join。
4).MySQL服务器调优及各个参数的设置(缓冲,线程数等)。
3.sql的执行顺序
手写的sql
SELECT <select_list> FROM <left_table><join_type> JOIN <right_table> ON <join_condition> WHERE <where_condition> GROUP BY <group_by_list> HAVING <having_condition> ORDER BY <order_by_condition> LIMIT <limit_number>
MySQL是怎么读的呢?(从from开始读)
FROM <left_table> ON <join_condition> <join_type> JOIN <right_table> WHERE <where_condition> GROUP BY <group_by_list> HAVING <having_condition> SELECT <select_list> ORDER BY <order_by_condition> LIMIT <limit_number>
WHERE和GROUP BY是一对哟~