2022.2.26
by 4K
今天回顾产品,想了解一个SQL第一次是什么时间执行的,最近一次是什么时间在这里插入代码片执行的。于是就网上搜资料。百度了很多,发现都是教你查看是否开启general_log。
目的也很简单,开启general_log所有的历史SQL就能获取。
其实,我们真的需要那么多用户日志吗?未必。
我们只需要有多少种SQL类型,最近执行的SQL即可。
select query,db,first_seen,last_seen from sys.statement_analysis;
详解:
26.4.3.35 The statement_analysis and x$statement_analysis Views
These views list normalized statements with aggregated statistics. The content mimics the MySQL Enterprise Monitor Query Analysis view. By default, rows are sorted by descending total latency.
The statement_analysis and x$statement_analysis views have these columns:
query – 规范化的SQL语句字符串。
db – 当前语句的默认数据库,无时为NULL
full_scan – 语句出现时执行的全表扫描的总次数。
exec_count – 语句执行的总次数。
err_count --语句出现时产生的错误总数。
warn_count – 语句出现时产生的警告总