当前位置:网站首页>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
边栏推荐
- 2.概率论-概率论公理
- Elaborate on the operation of idea
- 在线JSON转CSharp(C#)Class工具
- Spock sub piling
- [pit stepping record] a pit where the database connection is not closed and resources are released
- Which company would like to buy serious illness insurance in 2022?
- Friends of the week
- Nacos adapts Oracle11g create table DDL statement
- [2022 graduation season] from graduation to transition to the workplace
- MySQL (II) - MySQL data type
猜你喜欢

这道字符串反转的题目,你能想到更好的方法吗?

Sstable details

HCIP之路第八次实验

Yolov5 detecting small targets (with source code)

【星球精选】如何高效构建 Roam 与 theBrain 间细粒度双向链接?

HCIP之路MPLS

3DMAX plug-in development environment configuration and fileexport and utilities template testing

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

Friends of the week

启动appium
随机推荐
数学知识:快速幂—快速幂
The eighth experiment of hcip Road
CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准
快速排序 + 冒泡排序 + 插入排序 + 选择排序
What is customer experience automation?
一篇文章学会er图绘制
【Veusz】导入CSV中的二维数据
RFID data security experiment: C # visual realization of parity check, CRC redundancy check and Hamming code check
在kubernetes中部署kubersphere
[deep learning] [original] how to detect targets and draw map and other parameter maps without yolov5 weights or models
Ldconfig command
Guava Cache 使用小结
MySQL (II) - MySQL data type
Console Application
利用for循环输出一个字母三角形
Cirium has gradually become the standard for airlines' carbon dioxide emission reporting
论文伪代码规范,伪代码在线编辑器,
How bootstrap clears floating styles
这道字符串反转的题目,你能想到更好的方法吗?
How to solve CSRF attack in laravel