当前位置:网站首页>MySQL慢查询记录
MySQL慢查询记录
2022-06-23 07:11:00 【hzp666】
慢查询日志:MySQL慢查询日志记录下所有执行超过long_query_time时间的SQL语句,帮你找到执行慢的SQL,方便我们对这些SQL进行优化。慢查询日志的配置:
默认情况下,mysql没有启用慢查询日志。
[[email protected] ~]# mysql -u root -p
mysql> show variables like '%slow%';
+------------------------------------+------------------------------+
| Variable_name | Value |
+------------------------------------+------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_filter | |
| log_slow_rate_limit | 1 |
| log_slow_rate_type | session |
| log_slow_slave_statements | OFF |
| log_slow_sp_statements | ON |
| log_slow_verbosity | |
| max_slowlog_files | 0 |
| max_slowlog_size | 0 |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /var/lib/mysql/rh64-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+------------------------------+
16 rows in set (0.01 sec)1、可以配置my.cnf文件,服务启动时自动配置
[[email protected] ~]# cat /etc/my.cnf
重启server后,查看:
mysql> show variables like '%slow%';
2、在系统中配置slow-query-log
mysql> set @@global.slow_query_log = on;
mysql> show variables like '%slow%';
3、查看慢查询日志信息
[[email protected] mysql]# tail rh64-slow.log
记录没有使用索引的语句:
mysql> set @@global.log_queries_not_using_indexes=on;
Query OK, 0 rows affected (0.00 sec)
测试:
mysql> select count(*) from emp1 where empno=7788;
+----------+
| count(*) |
+----------+
| 688128 |
+----------+
1 row in set (4.03 sec)[[email protected] mysql]# tail rh64-slow.log
4、通过mysqldumpslow工具查看慢查询日志
[[email protected] mysql]# mysqldumpslow
[[email protected] mysql]# mysqldumpslow --help
[[email protected] mysql]# mysqldumpslow rh64-slow.log
按照平均锁定时间进行排序,查找前10名:
[[email protected] mysql]# mysqldumpslow -s al -n 10 rh64-slow.log
Reading mysql slow query log from rh64-slow.log
Count: 3 Time=0.00s (0s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
# Schema: prod Last_errno: N Killed: N
# Query_time: N.N Lock_time: N.N Rows_sent: N Rows_examined: N Rows_affected: N
# Bytes_sent: N
SET timestamp=N;
insert into emp1 select * from emp1
Count: 1 Time=0.00s (0s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
# Schema: prod Last_errno: N Killed: N
# Query_time: N.N Lock_time: N.N Rows_sent: N Rows_examined: N Rows_affected: N
# Bytes_sent: N
use prod;
SET timestamp=N;
insert into emp1 select * from emp1
Count: 1 Time=0.00s (0s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost
# Schema: prod Last_errno: N Killed: N
# Query_time: N.N Lock_time: N.N Rows_sent: N Rows_examined: N Rows_affected: N
# Bytes_sent: N
SET timestamp=N;
select count(*) from emp1 where empno=N
————————————————
原文链接:https://blog.csdn.net/weixin_42347763/article/details/113276922
边栏推荐
- Ntu-rgbd data set download and data format analysis
- 【星球精选】如何高效构建 Roam 与 theBrain 间细粒度双向链接?
- G++ compilation command use
- How to quickly and gracefully download large files from Google cloud disk (II)
- Spock sub piling
- [AI practice] xgbgressor model accelerates training and uses GPU to train xgbgressor in seconds
- 【唠嗑篇】普通人到底该怎么学技术啊?
- Ffplay realizes user-defined input stream playback
- U-Net: Convolutional Networks for Biomedical Image Segmentation
- MySQL summary
猜你喜欢

Nacos adapts to oracle11g- modify the source code of Nacos

Eureka服务注册与发现

Playwirght深度入门

3dmax插件开发环境配置及FileExport和Utilities模板测试

小爱音箱连接网络异常解决办法
![[cloud computing event] vocational skill competition -- container development example pig rapid development framework](/img/4b/393b5980090330602a501867c60089.png)
[cloud computing event] vocational skill competition -- container development example pig rapid development framework

MIT CMS.300 Session 12 – IDENTITY CONSTRUCTION 虚拟世界中身份认同的建立 part 2

Yan's DP analysis

聊聊服务治理中的路由设计

Qt工程报错:-1: error: Cannot run compiler ‘clang++‘. Output:mingw32-make.exe
随机推荐
unity转微信小程序小游戏
Wechat multiplayer chat and Roulette Games (websocket Implementation)
HCIP之路
How to solve CSRF attack in laravel
作为思摩尔应对气候变化紧急事件的一项举措,FEELM加入碳披露项目
279. perfect square
Unity picture loading and saving
Focusing on the industry, enabling customers | release of solutions for the five industries of the cloud container cloud product family
分布式ID生成
MySQL on duplicate key and PgSQL on conflict (primary key) handle primary key conflicts
【Kubernetes】Kubernetes各大版本的最新版本下载地址
Intelligence Education - how to merge codes when code conflicts occur in multi person collaborative development?
Judge black production based on CDN and client slow log characteristics
MySQL Niuke brush questions
G++ compilation command use
RFID data security experiment: C # visual realization of parity check, CRC redundancy check and Hamming code check
【唠嗑篇】普通人到底该怎么学技术啊?
The Sandbox 与《足球小将》达成合作,将流行的足球漫画及动画带入元宇宙
启动appium
three. Solution to stripe shadow and grid shadow in JS