mysql优化入门
  4KpIwPC5bsv0 2023年11月02日 34 0

查看慢sql

Select * from information_schema.processlist;

Show [full] processlist; 不加full只能显示前100字符 


通过慢日志

Slow query log 记录时间超过long_query_time的SQL

log_slow_admin_statements记录ALTER

TABLE, ANALYZE TABLE, CHECK TABLE, CREATE INDEX, DROP INDEX, OPTIMIZE TABLE, and REPAIR

TABLE

log_queries_not_using_indexes记录不使用的索引查询,限制参数log_throttle_queries_not_using_indexes,每分钟的记录数


慢查询的日志分析工具

mysqldumpslow mysql自带

pt-query-digest 参数比较丰富


通过Sys schema查询慢sql

需要performance_schema=ON

• UPDATE performance_schema.setup_consumers SET ENABLED = 'YES';

• UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES';

(影响性能)

一般x$开头是原始数据,其他开头为转换过的数据


schema_table_statistics表的改动和io

schema_tables_with_full_table_scans全表扫,优先优化

schema_auto_increment_columns自增主键

schema_index_statistics索引改动情况

schema_redundant_indexes schema_unused_indexes  冗余索引和未使用索引

statements_with_full_table_scans全表扫sql信息

statement_analysis sql汇总信息,events_statements_summary_by_digest数据来源

statements_with_errors_or_warnings error和warning sql  

statements_with_sorting statements_with_temp_tables临时表sql

statements_with_runtimes_in_95th_percentile  runtime在95%的SQL


查看运行时间最长的sql

select * from sys.statement_analysis order by

total_latency desc limit l\G


查看innodb_buffer_page会导致innodb buffer pool扫描影响性能


Explain analyze、explain  分析sql


若于执行计划不一致

optimizer trace查看


set optimizer_trace=‘enabled=on'

执行sql

select * from

information_schema.optimizer_trace;



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  xaeiTka4h8LY   2024年05月31日   36   0   0 MySQL索引
  xaeiTka4h8LY   2024年05月31日   46   0   0 MySQLSQL
  xaeiTka4h8LY   2024年05月31日   30   0   0 字段MySQL
  xaeiTka4h8LY   2024年05月31日   41   0   0 MySQL数据库
  xaeiTka4h8LY   2024年05月17日   52   0   0 数据库JavaSQL
  xaeiTka4h8LY   2024年05月17日   47   0   0 MySQLgithub
  xaeiTka4h8LY   2024年05月17日   52   0   0 数据库SQL
  xaeiTka4h8LY   2024年05月17日   38   0   0 MySQL数据库
4KpIwPC5bsv0