讀高效能mysql筆記

2021-07-10 12:02:00 字數 2123 閱讀 7257

效能監控的好工具 - newrelic 

效能分析的好工具 - percona-toolkit

show  variables like "%slow%"; 

show full processlist; 

set profiling=1; 

select * from `score_cal_unsuccessed`; 

show profiles; 

show profile for query 28; 

show status; 

show global status; //mysqladmin ext -i1 每秒執行一次 

flush status; 

explain select * from `score_cal_unsuccessed`; 

show status where variable_name like 'handler%' or variable_name like 'created%'; 

create table char_test(char_col varchar(10));/*char 去掉 string3後面的空格 但是varchar會保留*/ 

insert into char_test(char_col) values('string1'),(' string2'),('string3 '); 

select concat("'",char_col,"'") from char_test; 

drop table char_test; 

show variables like '%max_sort_length%'/*最大排序字長*/ 

select sql_no_cache count(*) from a join b using(列1,列2,列3)

show create table `activity_group0` /*這個表的sql建立語句*/ 

on duplicate key update

語法 如果在insert語句末尾指定了on duplicate key update,並且插入行後會導致在乙個unique索引或primary key中出現重複值,則在出現重複值的行執行update;如果不會導致唯一值列重複的問題,則插入新行。 

例如,如果列 a 為 主鍵 或 擁有unique索引,並且包含值1,則以下兩個語句具有相同的效果: 

複製** **如下: 

insert into table (a,c) values (1,3) on duplicate key update c=c+1; 

update table set c=c+1 where a=1; 

if 語法

update daily_hit_counter as c 

inner join ( 

select day,sum(cnt) as cnt,min(slot) as mslot 

from daily_hit_counter 

group by day 

) as x using(day) 

set c.cnt=if(c.slot=x.mslot,x.cnt,0) 

set c.slot=if(c.slot=x.mslot,0,c.slot) 

<=>操作符

'a' is null     ==> 'a' <=> null 

'a' is not null ==> not('a' <=> null) 

explain extended select * from `score_cal_unsuccessed` 

show warnings; 可以看到重構出的查詢語句。 

「straight_join」強制連線(join)順序 

效能分析工具

percona-toolkit

的編譯安裝方式: 

tar xzvf percona-toolkit-2.1.1.tar.gz 

cd percona-toolkit-2.1.1 

perl makefile.pl 

make 

make install 

使用: 

pt-query-digest slow.log 

pt-query-digest --processlist h=host1

建立高效能索引 《高效能Mysql》筆記2

crate table people last name varchar 50 not null,first name varchar 50 not null,dob date not null,gender enum m f not null,key last name,first name,do...

《高效能MySQL》筆記(2)

mysql儲存 的四種形式 1.觸發器 2.儲存過程 3.函式 4.在定時任務中存放 5.1開始 即事件 儲存過程和儲存函式可以接收引數然後返回值,但是觸發器和事件卻不行 mysql儲存過程 儲存過程 是一組為了完成特定功能的sql語句集,經編譯後儲存在資料庫中,使用者通過指定儲存過程的名字並給定引...

高效能Mysql筆記 優化

了解查詢的整個生命週期,清楚每個階段的時間消耗情況 參考select profiling 檢視profiling是否開啟 set profiling 1 開啟profiling show profiles 檢視每條查詢的效能 show profile for query id 檢視query id的...