邏輯架構(gòu)
-
MySQL系統(tǒng)架構(gòu)圖
系統(tǒng)架構(gòu)圖
-
MySQL邏輯架構(gòu)圖
邏輯架構(gòu)圖
show_profile執(zhí)行周期
- 修改配置
# 修改配置文件/etc/my.cf努酸,新增一行
query_cache_type=1
# 重啟mysql
systemctl restart mysqld
# 查看mysql啟動狀態(tài)
systemctl status mysqld
- 開啟profiling
# 先查看profiling狀態(tài)
mysql> show variables like '%profiling%';
# 開啟profiling
mysql> set profiling =1;
- 查看執(zhí)行周期
# 執(zhí)行一條sql,然后可以查看執(zhí)行計劃阻问。
mysql> select * from mytbl2 where id =2;
mysql> show profiles ;
mysql> show profile cpu ,block io for query Query_ID;
- sql執(zhí)行順序
select distinct
<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>
- 總結(jié)
多次執(zhí)行相同sql時柴淘,查詢緩存中的數(shù)據(jù)磨确。只能是相同sql谒养,因為類似redis存儲的是鍵值對。
存儲引擎
- 查看數(shù)據(jù)庫引擎
mysql> show engines;
- MyISAM和InnoDB對比
對比項 | MyISAM | InnoDB |
---|---|---|
外鍵 | 不支持 | 支持 |
事務(wù) | 不支持 | 支持 |
行表鎖 | 表鎖搁吓,即使操作一條紀錄也會鎖住整個表,不適合高并發(fā)操作 | 行鎖吭历,操作時只鎖定某一行,不對其他行有影響 |
緩存 | 只緩存索引擂橘,不緩存真是數(shù)據(jù) | 不僅緩存索引還要緩存真實數(shù)據(jù)晌区,對內(nèi)存要求較高,而且內(nèi)存大小對性能有決定行的影響 |
關(guān)注點 | 節(jié)省資源通贞、消耗少朗若、簡單業(yè)務(wù) | 并發(fā)寫、事務(wù)昌罩、更大資源 |
默認安裝 | Y | Y |
默認使用 | Y | Y |
自帶系統(tǒng)表使用 | Y | N |
其他配置
- 建表
create table mytbl2 (id int,name varchar(200), age int ,dept int);
insert into mytbl2 values (1,'zhang3',33,101);
insert into mytbl2 values (2,'li4',34,101);
insert into mytbl2 values (3,'wang5',34,102);
insert into mytbl2 values (4,'zhao6',34,102);
insert into mytbl2 values (5,'tian7',36,102);
# 錯誤查詢
SELECT name, dept, max(age) from mytbl2 group by dept;
# 正確查詢
select * from mytbl2 m inner join (
select dept, max(age) maxage from mytbl2 group by dept
) ab on ab.dept = m.dept and m.age=ab.maxage;
group by使用原則:select后面只能放函數(shù)和group by后相關(guān)的字段
- 查看sql_mode
show variables like 'sql_mode';