当前位置:网站首页>sql分析(查询截取分析做sql优化)
sql分析(查询截取分析做sql优化)
2022-06-28 07:48:00 【Fairy要carry】
目录

mysqldump的使用(慢查询分析)
1.开启慢查询日志
SHOW VARIABLES LIKE 'slow_query_log';
#开启慢查询日志
SET GLOBAL slow_query_log=1;
#慢查询的阈值
SHOW VARIABLES LIKE 'long_query_time';
SET long_query_time=0.1
2.先找到慢查询日志
cd /var/lib/mysql找到common.sock文件里面就是慢查询日志

3.使用日志分析工具
mysqldumpsslw --help
像我们一般分析sql优化就可以使用该日志分析
比如:查找最慢的三条
mysqldumpslow -s c -t 3 -a
3. 查到对应的sql之后再去集中处理,可以去sql控制台中explain该sql,然后进行sql索引优化
mysqldumpslow参数分析

工作常用参考:
得到返回记录集最多的10个SQL
mysqldumpslow -s r -t 10 /var/lib/mysql/atguigu-slow.log
得到访问次数最多的10个SQL
mysqldumpslow -s c -t 10 /var/lib/mysql/atguigu-slow.log
得到按照时间排序的前10条里面含有左连接的查询语句
mysqldumpslow -s t -t 10 -g "left join" /var/lib/mysql/atguigu-slow.log
另外建议在使用这些命令时结合 | 和more 使用 ,否则有可能出现爆屏情况
mysqldumpslow -s r -t 10 /var/lib/mysql/atguigu-slow.log | more
杀死用户
#查看用户进程
SHOW PROCESSLIST
KILL 3
视图
只负责展示,不需要发布程序

1.创建视图
CREATE VIEW view_name
AS
SELECT column_name(s)
FROM table_name
WHERE condition
2.创建完视图后,我们以后的查询直接在视图中查询即可(本身这个视图里面封装的就是我们的sql)
查看视图
DELIMITER $$
ALTER ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `view_test` AS
SELECT
`t_emp`.`id` AS `id`,
`t_emp`.`name` AS `name`,
`t_emp`.`age` AS `age`,
`t_emp`.`deptld` AS `deptld`,
`t_emp`.`empno` AS `empno`
FROM `t_emp`$$
DELIMITER ;根据视图进行查询得到数据
SELECT * FROM view_test边栏推荐
- Tencent continued to lay off staff in the second half of the year, and all business groups reduced by at least 10%. What do you think of this? Followers
- Software design of power control board
- Cloud native (to be updated)
- Generation and verification of JWT token
- Hj21 simple password
- NDK cross compilation
- Is it reliable to register and open an account for stock speculation? Is it safe?
- R language ggmap visual cluster
- kubelet驱逐机制的源码分析
- Section 8: DMA of zynq
猜你喜欢

Hack the box:routerspace

Software design of power control board

Modifying MySQL user name root under Linux

ACM笔记

Sentinel mechanism of redis cluster

Idea package together, using compact middle packages to solve &

SOC timer and interrupt configuration

Introduction and several months' experience of extending the solution thanos of Prometheus

A single node obtains the lock lock of the order number

Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
随机推荐
asp. Net datalist when there are multiple data displays
Kubelet garbage collection (exiting containers and unused images) source code analysis
kubernetes集群命令行工具kubectl
Conversion between HJ integer and IP address
卸载重装最新版mysql数据库亲测有效
Is it safe to open an account on Dongfang fortune
股票炒股注册开户靠谱吗?安全吗?
HJ prime factor
HJ string sort
What is EC blower fan?
Static resource compression reduces bandwidth pressure and increases access speed
flex布局
Soft test -- software designer -- database design of afternoon questions
Flex layout
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
Section 5: zynq interrupt
HJ整数与IP地址间的转换
HJ字符串排序
ACM notes
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)