mysql中如何查看sql語句的執(zhí)行時(shí)間
一、初始sql準(zhǔn)備
初始化表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
-- 用戶表 create table t_users( id int primary key auto_increment, -- 用戶名 username varchar (20), -- 密碼 password varchar (20), -- 真實(shí)姓名 real_name varchar (50), -- 性別 1表示男 0表示女 sex int , -- 出生年月日 birth date , -- 手機(jī)號 mobile varchar (11), -- 上傳后的頭像路徑 head_pic varchar (200) ); |
初始化數(shù)據(jù)
1
2
3
4
5
6
7
|
--添加用戶數(shù)據(jù) insert into t_users values ( null , 'whj' , '123456' , '王恒杰' ,1,now(), '12345678901' , 'boy.jpg' ); insert into t_users values ( null , 'dzw' , '123456' , '鄧正武' ,1,now(), '12345678901' , 'boy.jpg' ); insert into t_users values ( null , 'yfj' , '123456' , '楊福君' ,1,now(), '12345678901' , 'girl.jpg' ); insert into t_users values ( null , 'zx' , '123456' , '張西' ,1,now(), '12345678901' , 'girl.jpg' ); insert into t_users values ( null , 'zxj' , '123456' , '周宣君' ,0,now(), '12345678901' , 'boy.jpg' ); insert into t_users values ( null , 'lfk' , '123456' , '劉福昆' ,1,now(), '12345678901' , 'boy.jpg' ); |
表結(jié)構(gòu)
相關(guān)數(shù)據(jù)
二、mysql查看sql語句的執(zhí)行時(shí)間
1、show profiles;
最開始輸入show profiles.此時(shí)沒有數(shù)據(jù)
2、show variables;
show varables:查看profiling是否開啟,即value為on
直接使用show variables命令會(huì)將所有變量展示出來,太多了,我們不方便查看
就可以使用模糊查詢了,用like將profiling挑選出來
一般沒有開啟都為off
1
|
show variables like 'profiling' ; |
3、set profilling=1
,開啟profiling
1
|
show variables like 'profiling' ; |
這樣我們的mysql就可以查看sql語句的執(zhí)行時(shí)間
三、不同查詢的執(zhí)行時(shí)間
1
2
3
4
|
select * from t_users; select id,username, password ,real_name,sex,birth,mobile,head_pic from t_users; select * from t_users where username like 'whj' ; |
三種查詢的時(shí)間對比
結(jié)論:
sql 在使用select語句或者使用其它語句時(shí),直接使用*和把所有的字段弄上去查詢,性能有很大差距,所以我們平時(shí)寫查詢最好用字段寫上
總結(jié)
到此這篇關(guān)于mysql中如何查看sql語句的執(zhí)行時(shí)間的文章就介紹到這了,更多相關(guān)mysql查看sql語句執(zhí)行時(shí)間內(nèi)容請搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://blog.csdn.net/weixin_44385486/article/details/121914768