当前位置:网站首页>MySQL slow query record

MySQL slow query record

2022-06-23 07:49:00 hzp666

Slow query log :MySQL The slow query log records that all executions exceed long_query_time The time of the SQL sentence , Help you find the slow execution SQL, For our convenience SQL To optimize . Slow query log configuration :

By default ,mysql Slow query log is not enabled .

[[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、 You can configure the my.cnf file , Automatic configuration at service startup

[[email protected] ~]# cat /etc/my.cnf

restart server after , see :

mysql> show variables like '%slow%';

2、 Configure... In the system slow-query-log

mysql> set @@global.slow_query_log = on;

mysql> show variables like '%slow%';

3、 View slow query log information

[[email protected] mysql]# tail rh64-slow.log

Record statements that do not use indexes :

mysql> set @@global.log_queries_not_using_indexes=on;

Query OK, 0 rows affected (0.00 sec)

test :

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、 adopt mysqldumpslow Tools to view slow query logs

[[email protected] mysql]# mysqldumpslow

[[email protected] mysql]# mysqldumpslow --help

[[email protected] mysql]# mysqldumpslow rh64-slow.log

Sort by average lock time , Before searching 10 name :

[[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
————————————————

Link to the original text :https://blog.csdn.net/weixin_42347763/article/details/113276922

原网站

版权声明
本文为[hzp666]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230711200492.html