MySQL學習筆記(三)數據優化
阿新 • • 發佈:2018-05-27
繼續 水平拆分 索引 mys explain del dumps simple 學習筆記
第1章 數據庫優化簡介
1-1 MySQL優化簡介
第2章 SQL語句優化
2-1 數據準備
2-2 MySQL慢查日誌的開啟方式
2-3 MySQL慢查日誌分析工具之 mysqldumpslow
www@AliYun:~$ sudo mysqldumpslow -t 3 /var/log/mysql/slow.log | more Reading mysql slow query log from /var/log/mysql/slow.log Count: 1 Time=0.16s (0s) Lock=0.00s (0s) Rows=0.0 (0), www[www]@[115.193.170.169] DELETE FROM `resty_invitation` Count: 1 Time=0.14s (0s) Lock=0.00s (0s) Rows=1000.0 (1000), www[www]@[115.193.170.169] SELECT * FROM `resty_logs` LIMIT N, N Count: 2 Time=0.05s (0s) Lock=0.01s (0s) Rows=0.0 (0), []@[] throttle: N ‘S‘ warning(s) suppressed.
2-4 MySQL慢查日誌分析工具之 pt-querey-diget
2-5 如何通過慢查日誌發現有問
2-6 通過explain查詢和分析SQL的執行計劃
mysql> explain select username,logintime,status,expire from resty_user limit 4; +----+-------------+------------+------------+------+---------------+------+---------+------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------+------------+------+---------------+------+---------+------+------+----------+-------+ | 1 | SIMPLE | resty_user | NULL | ALL | NULL | NULL | NULL | NULL | 9 | 100.00 | NULL | +----+-------------+------------+------------+------+---------------+------+---------+------+------+----------+-------+ 1 row in set, 1 warning (0.01 sec)
2-7 Count()和Max()的優化
mysql> explain select MAX(fileSize) from resty_stream_video \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: resty_stream_video partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 177 filtered: 100.00 Extra: NULL 1 row in set, 1 warning (0.00 sec)
建立索引
create index idx_fileSize on resty_stream_video(fileSize);
繼續查詢
mysql> explain select MAX(fileSize) from resty_stream_video \G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: NULL
partitions: NULL
type: NULL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
filtered: NULL
Extra: Select tables optimized away
1 row in set, 1 warning (0.00 sec)
count(*)和count(某一列) 那個好?
mysql> select * from test;
+------+
| id |
+------+
| 1 |
| 2 |
| NULL |
+------+
3 rows in set (0.00 sec)
mysql> select count(*),count(id) from test;
+----------+-----------+
| count(*) | count(id) |
+----------+-----------+
| 3 | 2 |
+----------+-----------+
1 row in set (0.00 sec)
小結:count(某一列) 不包括為null的值
2-8 子查詢的優化
2-9 group by的優化
2-10 Limit查詢的優化
第3章 索引優化
3-1 如何選擇合適的列建立索引...(03:25)
3-2 索引優化SQL的方法(07:17)
3-3 索引維護的方法(02:43)
第4章 數據庫結構優化
4-1 選擇合適的數據類型...(06:43)
4-2 數據庫表的範式化優化...(05:03)
4-3 數據庫表的反範式化優化...(04:23)
4-4 數據庫表的垂直拆分...(02:59)
4-5 數據庫表的水平拆分...(03:13)
第5章 系統配置優化
5-1 數據庫系統配置優化...(04:24)
5-2 MySQL配置文件優化(10:26)
5-3 第三方配置工具使用...(06:17)
第6章 服務器硬件優化
6-1 服務器硬件優化(05:59)
MySQL學習筆記(三)數據優化