当前位置:网站首页>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
边栏推荐
- 数学知识:快速幂求逆元—快速幂
- 在kubernetes中部署kubersphere
- [AI practice] xgbgressor model accelerates training and uses GPU to train xgbgressor in seconds
- 聊聊服务治理中的路由设计
- C WPF realizes dynamic loading of controls through binding
- [game theory] basic knowledge
- YGG 西班牙 subDAO——Ola GG 正式成立
- Detailed explanation of redis persistence, master-slave and sentry architecture
- JS to determine the added and decreased elements of two arrays
- 【PyQt5系列】修改计数器实现控制
猜你喜欢

3dmax插件开发环境配置及FileExport和Utilities模板测试
![[game theory] basic knowledge](/img/eb/08b1ce5106e574dc42be58f72fbab9.jpg)
[game theory] basic knowledge

MySQL on duplicate key and PgSQL on conflict (primary key) handle primary key conflicts
![[deep learning] [original] how to detect targets and draw map and other parameter maps without yolov5 weights or models](/img/f3/ff14cb5439a24e26f977e5f0d15785.png)
[deep learning] [original] how to detect targets and draw map and other parameter maps without yolov5 weights or models

Simpledateformat thread safety issues

【PyQt5系列】修改计数器实现控制

Abnormal logic reasoning problem of Huawei software test written test

在线文本过滤小于指定长度工具

Sstable details

How to tag and label naming before the project release
随机推荐
【markdown】markdown 教程大归纳
Ldconfig command
The road to hcip MPLS
Spock sub piling
[* * * array * * *]
Data types in tensorflow
What is the experience of being a data product manager in the financial industry
电脑如何安装MySQL?
Spock constraint - call frequency / target / method parameters
[AI practice] xgb Xgbregression multioutputregressor parameter 2 (GPU training model)
HCIP之路MPLS
unity 音频可视化方案
Pseudocode specification, pseudocode online editor,
leetcode210. Schedule II 207 Curriculum topology sorting DFS BFS
Unity picture loading and saving
unity转微信小程序小游戏
RFID data security experiment: C # visual realization of parity check, CRC redundancy check and Hamming code check
[pit stepping record] a pit where the database connection is not closed and resources are released
Unity to wechat applet games
聊聊服务治理中的路由设计