MySQL sys Schema
使用sys Schemamysql
MySQL 5.7.7及更高版本包括sys schema,这是一组帮助DBA和开发人员解释Performance schema收集的数据的对象。 sys schema对象可用于典型的调优和诊断用例。 此schema中的对象包括:session
将Performance Schema数据汇总为更易于理解的形式的视图。函数
执行诸如 Performance Schema 配置和生成诊断报告等操做的存储过程。工具
存储函数,用于查询 Performance Schema 配置并提供格式化服务。ui
在新安装MySQL实例时,若是将mysqld
与--initialize
或--initialize-insecure
选项一块儿使用,则在数据目录初始化期间默认安装sys schema。若是不须要,能够在初始化后手动删除sys schema。url
在升级MySQL时,mysql_upgrade会安装sys schema(若是未安装),不然将其升级到当前版本。若是不想安装或升级,可使用:mysql_upgrade
选项--skip-sys-schema
。spa
若是存在sys schema但没有version
视图,mysql_upgrade会返回错误,前提是缺乏此视图表示用户建立的sys schema。要在这种状况下进行升级,请先删除或重命名现有的sys schema。
从MySQL 5.7.9开始,sys schema对象的DEFINER为’mysql.sys’@’localhost’。 (在MySQL 5.7.9以前,DEFINER是’root’@’localhost’。)使用专用的mysql.sys
账户能够避免DBA重命名或删除root账户时出现的问题。
sys Schema 视图
- host_summary 与 x$host_summary
- host_summary_by_file_io 与 x$host_summary_by_file_io
- host_summary_by_file_io_type 与 x$host_summary_by_file_io_type
- 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
- innodb_buffer_stats_by_schema 与 x$innodb_buffer_stats_by_schema
- innodb_buffer_stats_by_table 与 x$innodb_buffer_stats_by_table
- innodb_lock_waits 与 x$innodb_lock_waits
- io_by_thread_by_latency 与 x$io_by_thread_by_latency
- io_global_by_file_by_bytes 与 x$io_global_by_file_by_bytes
- io_global_by_file_by_latency 与 x$io_global_by_file_by_latency
- io_global_by_wait_by_bytes 与 x$io_global_by_wait_by_bytes
- io_global_by_wait_by_latency 与 x$io_global_by_wait_by_latency
- latest_file_io 与 x$latest_file_io
- 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
- metrics
- processlist 与 x$processlist
- ps_check_lost_instrumentation
- schema_auto_increment_columns
- schema_index_statistics 与 x$schema_index_statistics
- schema_object_overview
- schema_redundant_indexes 与 x$schema_flattened_keys
- schema_table_lock_waits 与 x$schema_table_lock_waits
- schema_table_statistics 与 x$schema_table_statistics
- schema_table_statistics_with_buffer 与 x$schema_table_statistics_with_buffer
- schema_tables_with_full_table_scans 与 x$schema_tables_with_full_table_scans
- schema_unused_indexes
- session 与 x$session
- session_ssl_status
- statement_analysis 与 x$statement_analysis
- statements_with_errors_or_warnings 与 x$statements_with_errors_or_warnings
- statements_with_full_table_scans 与 x$statements_with_full_table_scans
- statements_with_runtimes_in_95th_percentile 与 x$statements_with_runtimes_in_95th_percentile
- statements_with_sorting 与 x$statements_with_sorting
- statements_with_temp_tables 与 x$statements_with_temp_tables
- user_summary 与 x$user_summary
- user_summary_by_file_io 与 x$user_summary_by_file_io
- user_summary_by_file_io_type 与 x$user_summary_by_file_io_type
- user_summary_by_stages 与 x$user_summary_by_stages
- user_summary_by_statement_latency 与 x$user_summary_by_statement_latency
- user_summary_by_statement_type 与 x$user_summary_by_statement_type
- version
- wait_classes_global_by_avg_latency 与 x$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
如下部分描述了sys schema视图。
sys模式包含许多视图,这些视图以各类方式汇总了Performance Schema表。 这些视图中的大多数成对出现,使得该对中的一个成员具备与另外一个成员相同的名称,加上x$前缀。 例如,host_summary_by_file_io视图汇总了按主机分组的文件I/O,并显示从皮秒转换为更可读的值(带单位)的延迟;
mysql> SELECT * FROM sys.host_summary_by_file_io; +------------+-------+------------+ | host | ios | io_latency | +------------+-------+------------+ | localhost | 67570 | 5.38 s | | background | 3468 | 4.18 s | +------------+-------+------------+ x$host_summary_by_file_io视图汇总了相同的数据,但显示了未格式化的皮秒延迟: mysql> SELECT * FROM sys.x$host_summary_by_file_io; +------------+-------+---------------+ | host | ios | io_latency | +------------+-------+---------------+ | localhost | 67574 | 5380678125144 | | background | 3474 | 4758696829416 | +------------+-------+---------------+
没有x$
前缀的视图旨在提供更加用户友好且更易于阅读的输出。 带有x$
前缀的视图以原始形式显示相同的值,更适合与对数据执行本身处理的其余工具一块儿使用。
没有x$
前缀的视图在这些方面与相应的x$
视图不一样:
字节值使用
format_bytes()
以大小单位格式化。使用
format_time()
以时间单位格式化时间值。使用
format_statement()
将SQL语句截断为最大显示宽度。使用
format_path()
缩短路径名。