0
点赞
收藏
分享

微信扫一扫

mysql优化入门

查看慢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;



举报

相关推荐

0 条评论