当前位置:网站首页>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边栏推荐
- Study notes 22/1/11
- Redis implements distributed locks
- HJ字符串排序
- 22/02/14 study notes
- Investment transaction and settlement of the fund
- HJ character count
- R language Kolmogorov Smirnov tests whether the two samples follow the same distribution.
- kubelet垃圾(退出的容器和未使用的镜像)回收源码分析
- Ice - resources
- kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
猜你喜欢

阿里云服务器创建快照、回滚磁盘

Hack the box:routerspace

Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)

Block transmission by golang gin framework

kubernetes集群命令行工具kubectl

安全培训是员工最大的福利!2022新员工入职安全培训全员篇

asp. Net to search products and realize paging function

Disposition Flex

Generation and verification of JWT token

Unity UI shadow component
随机推荐
MMR rearrangement (similarity is calculated by editing distance and repeatability)
Software design of power control board
QT -- communication protocol
Section VII starting principle and configuration of zynq
Uninstall and reinstall the latest version of MySQL database. The test is valid
R and RGL draw 3D knots
Kubelet garbage collection (exiting containers and unused images) source code analysis
golang gin框架进行分块传输
HJ delete the character with the least number of occurrences in the string
Application of XOR. (extract the rightmost 1 in the number, which is often used in interviews)
Design and implementation of spark offline development framework
分析 NFT 项目的 5 个指标
R language ggmap
HJ删除字符串中出现次数最少的字符
Cloud native (to be updated)
Section VI UART of zynq
R language drawing ggplot2 seasonal graph
Kubernetes理论基础
股票炒股注册开户靠谱吗?安全吗?
Open62541 import nodeset file directly