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()
縮短路徑名。