图文详解Mysql中如何查看Sql语句的执行时间

吾爱主题 阅读:111 2024-04-02 18:53:33 评论:0
目录
  • 一、初始sql准备
  • 二、mysql查看sql语句的执行时间
  • 三、不同查询的执行时间
  • 总结

mysql中如何查看sql语句的执行时间

一、初始sql准备

初始化表

?
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), -- 真实姓名                          real_name varchar (50), -- 性别 1表示男  0表示女                          sex int , -- 出生年月日                          birth date , -- 手机号                          mobile varchar (11), -- 上传后的头像路径                          head_pic varchar (200) );

初始化数据

?
1 2 3 4 5 6 7 --添加用户数据 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' );

表结构

相关数据

二、mysql查看sql语句的执行时间

1、show profiles;

最开始输入show profiles.此时没有数据

2、show variables; show varables:查看profiling是否开启,即value为on

直接使用show variables命令会将所有变量展示出来,太多了,我们不方便查看

就可以使用模糊查询了,用like将profiling挑选出来

一般没有开启都为off

?
1 show variables like 'profiling' ;

3、set profilling=1,开启profiling

?
1 show variables like 'profiling' ;

这样我们的mysql就可以查看sql语句的执行时间

三、不同查询的执行时间

?
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' ;

三种查询的时间对比

结论:

sql 在使用select语句或者使用其它语句时,直接使用*和把所有的字段弄上去查询,性能有很大差距,所以我们平时写查询最好用字段写上

总结

到此这篇关于mysql中如何查看sql语句的执行时间的文章就介绍到这了,更多相关mysql查看sql语句执行时间内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_44385486/article/details/121914768

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容