MySQL sys库常用SQL汇总大全

查看当前连接情况:

select host, current_connections,statements from sys.host_summary;



查看当前正在执行的SQL:

select conn_id, user, current_statement, last_statement from sys.session;


查看系统里执行最多的TOP 10 SQL:

select * from sys.statement_analysis order by exec_count desc limit 10 \G


查看系统里哪张表的IO最多:

select * from sys.io_global_by_file_by_bytes limit 10;


查看系统里哪张表访问次数最多:

select * from sys.statement_analysis order by exec_count desc limit 10 \G


查看哪些语句延迟比较严重:

select * from sys.statement_analysis order by avg_latency desc limit 10 \G


查看系统里未使用过的索引:

select * from sys.schema_unused_indexes;


查看系统里冗余的索引:

select table_schema,table_name,redundant_index_name,redundant_index_columns,dominant_index_name,dominant_index_columns from sys.schema_redundant_indexes;


哪些SQL语句使用了磁盘临时表:

select db, query, tmp_tables,tmp_disk_tables from sys.statement_analysis where tmp_tables>0 or tmp_disk_tables >0 order by(tmp_tables+tmp_disk_tables) desc limit 20;


查看哪张表占用了最多的buffer pool:

select * from sys.innodb_buffer_stats_by_table order by pages desc limit 10 \G


查看每个库占用多少buffer pool:

select * from sys.innodb_buffer_stats_by_schema;


查看每个连接分配多少内存:

select b.user, current_count_used,current_allocated, current_avg_alloc, current_max_alloc,total_allocated,current_statement from sys.memory_by_thread_by_current_bytes a,sys.session b where a.thread_id = b.thd_id;



查看MySQL内部的线程类型及数量:

select user, count(*) from sys.processlist group by user;


查看表自增ID情况:

select * from sys.schema_auto_increment_columns limit 10;



附:sys库视图和指标详解

视图                                                                                  说明

host_summary,x $ host_summary                                 统计以主机为分组统计活动的语句,文件I / O,连接等信息

host_summary_by_file_io,x $ host_summary_by_file_io                  文件IO

host_summary_by_file_io_type,x $ host_summary_by_file_io_type        主机和事件类型的文件I / O

host_summary_by_stages,x $ host_summary_by_stages                   按照主机分类的语句阶段执行信息

host_summary_by_statement_latency,x $ host_summary_by_statement_latency 按照主机分类的语句统计

host_summary_by_statement_type,x $ host_summary_by_statement_type       按照主机和SQL执行的语句信息

innodb_buffer_stats_by_schema,x $ innodb_buffer_stats_by_schema       按照架构统计InnoDB缓冲区信息

innodb_buffer_stats_by_table,x $ innodb_buffer_stats_by_table         按照schema和表统计InnoDB缓冲区信息

innodb_lock_waits,x $ innodb_lock_waits                                  InnoDB锁锁信息

io_by_thread_by_latency,x $ io_by_thread_by_latency                        线程消耗IO

io_global_by_file_by_bytes,x $ io_global_by_file_by_bytes                 文件IO消耗大小信息

io_global_by_file_by_latency,x $ io_global_by_file_by_latency             文件IO延迟信息

io_global_by_wait_by_bytes,x $ io_global_by_wait_by_bytes               按照大小(字节)的全局I / O消耗

io_global_by_wait_by_latency,x $ io_global_by_wait_by_latency           IO消耗的延迟信息

latest_file_io,x $ latest_file_io                                       最近使用文件I / O信息

memory_by_host_by_current_bytes,x $ memory_by_host_by_current_bytes     主机使用内存信息

memory_by_thread_by_current_bytes,x $ memory_by_thread_by_current_bytes 线程使用内存信息

memory_by_user_by_current_bytes,x $ memory_by_user_by_current_bytes          用户使用内存信息

memory_global_by_current_bytes,x $ memory_global_by_current_bytes              内存使用分配的类型

memory_global_total,x $ memory_global_total                                    内存统计信息


指标说明                                                                                                             

processlist,x $ processlist                                                 Processlist进程信息

ps_check_lost_instrumentation                                                  丢失的性能模式工具的信息

schema_auto_increment_columns                                                    AUTO_INCREMENT自增长列信息

schema_index_statistics,x $ schema_index_statistics                          索引统计信息

schema_object_overview                                                          每个模式的对象类型

schema_redundant_indexes                                                        重复/冗余的索引

schema_table_lock_waits,x $ schema_table_lock_waits                              等待MDL的会话

schema_table_statistics,x $ schema_table_statistics                             表统计信息

schema_table_statistics_with_buffer,x $ schema_table_statistics_with_buffer 表统计信息,包含InnoDB缓冲池统计信息

schema_tables_with_full_table_scans,x $ schema_tables_with_full_table_scans 全表访问的表

schema_unused_indexes                                                            没有使用的索引

session,x $ session                                                           用户会话的Processlis信息

session_ssl_status                                                                 SSL连接信息

statement_analysis,x $ statement_analysis                                       SQL语句汇总信息统计

statements_with_errors_or_warnings,x $ statements_with_errors_or_warnings        含有错误和警告的SQL

statements_with_full_table_scans,x $ statements_with_full_table_scans             执行时候全表扫描的语句

statements_with_runtimes_in_95th_percentile,X $ statements_with_runtimes_in_95th_percentile 平均运行时间很长的SQL

statements_with_sorting,x $ statements_with_sorting                                        排序的SQL语句

statements_with_temp_tables,x $ statements_with_temp_tables                          使用临时表的SQL玉溪

user_summary,x $ user_summary                                                        用户语句和活动连接信息

user_summary_by_file_io,x $ user_summary_by_file_io                                  用户相关文件I / O信息

user_summary_by_file_io_type,x $ user_summary_by_file_io_type                          用户相关文件FI / O类型信息

user_summary_by_stages,x $ user_summary_by_stages                                      用户阶段事件和延迟信息

user_summary_by_statement_latency,x $ user_summary_by_statement_latency             以统计的SQL语句信息

user_summary_by_statement_type,x $ user_summary_by_statement_type                   按照用户和事件(事件)已执行的SQL语句信息

wa_ wait_classes_global_by_avg_latency                                               事件类型分类的平均延迟

wait_classes_global_by_latency,x $ wait_classes_global_by_latency                   事件类型的延迟统计

waits_by_host_by_latency,x $ waits_by_host_by_latency                               按照主机分类的事件系想你

waits_by_user_by_latency,x $ waits_by_user_by_latency                               按用户统计的事件

waits_global_by_latency,x $ waits_global_by_latency                               按事件统计的事件信息


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2643654/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2643654/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值