MySQL的SYS视图

MySQL8.0的发展越来越趋同与Oracle,为了更好的监控MySQL的一些相关指标,出现了SYS视图,用于监控。

1.MySQL版本

(root@localhost) [sys]> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.11 |
+-----------+
1 row in set (0.01 sec)

2.数据准备

(root@localhost) [ztest]> show create table zstudent;

| Table    | Create Table
+------------------------------------+
| zstudent | CREATE TABLE `zstudent` (
`stu_id` int(11) NOT NULL AUTO_INCREMENT,
`stu_name` varchar(20) DEFAULT NULL,
`sex` char(1) DEFAULT NULL,
PRIMARY KEY (`stu_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 |
+-------------------------------------+
1 row in set (0.00 sec) 创建索引:
(root@localhost) [ztest]> create index idx_stu_name on zstudent (stu_name);
(root@localhost) [ztest]> create unique index idx_stu_name2 on zstudent (stu_name);

sys包含了很多总结performance Schema表的视图,这些视图成对出现,并且有些以x$前缀出现。查看并使用sys的方式:

查看performance Schema表的视图

(root@localhost) [sys]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| ztest |
+--------------------+
5 rows in set (0.01 sec) (root@localhost) [sys]> use sys
Database changed
(root@localhost) [sys]> show tables;
+-----------------------------------------------+
| Tables_in_sys |
+-----------------------------------------------+
| host_summary |
| host_summary_by_file_io |
| host_summary_by_file_io_type |
| host_summary_by_stages |
| host_summary_by_statement_latency |
| host_summary_by_statement_type |
| innodb_buffer_stats_by_schema |
| innodb_buffer_stats_by_table |
| innodb_lock_waits |
| io_by_thread_by_latency |
...................

查看表的数据访问量

(root@localhost) [sys]> select table_schema,table_name,io_read_requests,io_write_requests from schema_table_statistics where table_schema='ztest';
+--------------+------------+------------------+-------------------+
| table_schema | table_name | io_read_requests | io_write_requests |
+--------------+------------+------------------+-------------------+
| ztest | zstudent | 0 | 14 |
| ztest | zstudent2 | 0 | 7 |
+--------------+------------+------------------+-------------------+
2 rows in set (0.05 sec)

查看索引的冗余

(root@localhost) [sys]> select * from sys.schema_redundant_indexes \G
*************************** 1. row ***************************
table_schema: ztest
table_name: zstudent
redundant_index_name: idx_stu_name
redundant_index_columns: stu_name
redundant_index_non_unique: 1
dominant_index_name: idx_stu_name2
dominant_index_columns: stu_name
dominant_index_non_unique: 0
subpart_exists: 0
sql_drop_index: ALTER TABLE `ztest`.`zstudent` DROP INDEX `idx_stu_name`
1 row in set (0.01 sec)

表自增ID监控

(root@localhost) [sys]> select * From schema_auto_increment_columns\G;
*************************** 1. row ***************************
table_schema: ztest
table_name: zstudent
column_name: stu_id
data_type: int
column_type: int(11)
is_signed: 1
is_unsigned: 0
max_value: 2147483647
auto_increment: 6
auto_increment_ratio: 0.0000
1 row in set (0.04 sec)

监控全表扫描的SQL语句

(root@localhost) [sys]> select * from statements_with_full_table_scans where db='ztest' \G
*************************** 1. row ***************************
query: SELECT * FROM `zstudent`
db: ztest
exec_count: 2
total_latency: 6.58 m
no_index_used_count: 2
no_good_index_used_count: 0
no_index_used_pct: 100
rows_sent: 10
rows_examined: 10
rows_sent_avg: 5
rows_examined_avg: 5
first_seen: 2018-05-19 17:03:03.306527
last_seen: 2018-05-19 18:36:51.142365
digest: 8800ada0600ed0790d89b6ab22e5bab762c3698d308346bb542c9b2c377c4114

查看当前接入的会话

(root@localhost) [sys]> select thd_id,conn_id,user,command,current_statement,current_memory From x$session\G;
*************************** 1. row ***************************
thd_id: 68
conn_id: 28
user: root@localhost
command: Sleep
current_statement: NULL
current_memory: 34950
*************************** 2. row ***************************
thd_id: 67
conn_id: 27
user: root@localhost
command: Query
current_statement: select thd_id,conn_id,user,command,current_statement,current_memory From x$session
current_memory: 1207007
*************************** 3. row ***************************
thd_id: 45
conn_id: 4
user: sql/event_scheduler
command: Sleep
current_statement: NULL
current_memory: 16569
3 rows in set (0.17 sec)

备注:current_memory ---The number of bytes allocated by the thread(当前这个线程所需要分配的内存,单位为byte)

查看当前接入的线程

(root@localhost) [sys]> select thd_id,conn_id,user,db,command,current_statement from x$processlist;

+--------+---------+--------------------------------------+-------+---------+----------------------------------------------------------------------------+
| thd_id | conn_id | user | db | command | current_statement |
+--------+---------+--------------------------------------+-------+---------+----------------------------------------------------------------------------+
| 27 | NULL | innodb/srv_master_thread | NULL | NULL | NULL |
| 29 | NULL | innodb/dict_stats_thread | NULL | NULL | NULL |
| 30 | NULL | innodb/fts_optimize_thread | NULL | NULL | NULL |
| 47 | 6 | sql/compress_gtid_table | NULL | Daemon | NULL |
| 34 | NULL | mysqlx/acceptor_network | NULL | NULL | NULL |
| 37 | NULL | innodb/srv_purge_thread | NULL | NULL | NULL |
| 38 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 39 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 41 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 1 | NULL | sql/main | mysql | NULL | NULL |
| 68 | 28 | root@localhost | ztest | Sleep | NULL |
| 67 | 27 | root@localhost | sys | Query | select thd_id,conn_id,user,db,command,current_statement from x$processlist |
| 40 | NULL | innodb/srv_purge_thread | NULL | NULL | NULL |
| 42 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 43 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 44 | NULL | innodb/srv_worker_thread | NULL | NULL | NULL |
| 45 | 4 | sql/event_scheduler | NULL | Sleep | NULL |
| 32 | NULL | mysqlx/worker | NULL | NULL | NULL |
| 31 | NULL | mysqlx/worker | NULL | NULL | NULL |
| 46 | NULL | sql/signal_handler | NULL | NULL | NULL |
| 28 | NULL | innodb/buf_dump_thread | NULL | NULL | NULL |
........................................

查看MySQL实例消耗的磁盘IO

(root@localhost) [sys]> select file,avg_read+avg_write as avg_io from io_global_by_file_by_bytes order by avg_io desc limit 10;
+----------------------------------------------+--------+
| file | avg_io |
+----------------------------------------------+--------+
| @@innodb_log_group_home_dir/ib_logfile0 | 642.62 |
| /data/mysqldata/3306/binlog/mysql-bin.000002 | 299 |
| @@innodb_data_home_dir/ibdata1 | 240.8 |
| /data/mysqldata/3306/slow_statement.log | 212 |
| /data/mysqldata/3306/binlog/mysql-bin.000001 | 119 |
| @@basedir/share/english/errmsg.sys | 83.65 |
| @@innodb_data_home_dir/ibtmp1 | 61.47 |
| @@datadir/undo_001 | 32.18 |
| @@datadir/undo_002 | 32.18 |
| @@datadir/mysql.ibd | 32.09 |
+----------------------------------------------+--------+
10 rows in set (0.49 sec)

知识点小注:当页面数据太多的时候,可以使用命令(root@localhost) [sys]> pager more;

【MySQL】MySQL 8.0的SYS视图的更多相关文章

  1. MySQL 5.7系列之sys schema(2)

    0.导读 MySQL 5.7引入了sys schema,有了它,我们排查分析一些问题时将更得心应手.sys schema里主要存储的是视图.存储过程.函数等. 视图:用于结果的汇总展示及配置持久化: ...

  2. 【mysql】mysq8.0新特性

    一.MySQL8.0简介   mysql8.0现在已经发布,2016-09-12第一个DM(development milestone)版本8.0.0发布.新的版本带来很多新功能和新特性,对性能也得到 ...

  3. MySQL 系列(三)你不知道的 视图、触发器、存储过程、函数、事务、索引、语句

    第一篇:MySQL 系列(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:MySQL 系列(二) 你不知道的数据库操作 第三篇:MySQL 系列(三)你不知道的 视图.触发器.存储过程.函数 ...

  4. 我的MYSQL学习心得(十一) 视图

    我的MYSQL学习心得(十一) 视图 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  5. 第七章 mysql 事务索引以及触发器,视图等等,很重要又难一点点的部分

    [索引] 帮助快速查询 MyISAM ,InnoDB支持btree索引 Memory 支持 btree和hash索引 存储引擎支持 每个表至少16个索引   总索引长度至少256字节   创建索引的优 ...

  6. MySQL/MariaDB表表达式(3):视图

    视图是表表达式的一种,所以它也是虚拟表.对视图操作的时候会通过语句动态的从表中临时获取数据. 1.创建.修改视图 CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED ...

  7. mysql基础教程(四)-----事务、视图、存储过程和函数、流程控制

    事务 概念 事务由单独单元的一个或多个SQL语句组成,在这 个单元中,每个MySQL语句是相互依赖的.而整个单独单 元作为一个不可分割的整体,如果单元中某条SQL语句一 旦执行失败或产生错误,整个单元 ...

  8. phpMyAdmin - 错误 您应升级到 MySQL 5.5.0 或更高版本,解决办法。。。

    折腾自己的个人网站,装了个数据库管理工具,遇到您应升级到 MySQL 5.5.0 或更高版本... 采用降级phpmyadmin版本的方法解决了: 查找phpmyadmin/libraries/com ...

  9. Export Data from mysql Workbench 6.0

    原文地址:export-data-from-mysql-workbench-6-0 问题描述 I'm trying to export my database, using MySQL Workben ...

随机推荐

  1. JMeter系列教程

    认识JMeter工具 JMeter常用元件功能介绍 JMeter线程组 JMeter脚本三种录制方法 Jmeter组件介绍及其作用域和执行顺序 JMeter参数化 JMeter集合点 JMeter关联 ...

  2. pytorch中的nn.CrossEntropyLoss()

    nn.CrossEntropyLoss()这个损失函数和我们普通说的交叉熵还是有些区别 x是模型生成的结果,class是对应的label 具体代码可参见如下 import torch import t ...

  3. 这可能是最漂亮的Spring事务管理详解

    事务概念回顾 什么是事务? 事务是逻辑上的一组操作,要么都执行,要么都不执行. 事物的特性(ACID): 原子性: 事务是最小的执行单位,不允许分割.事务的原子性确保动作要么全部完成,要么完全不起作用 ...

  4. go语言之range

    Go 语言范围(Range) Go 语言中 range 关键字用于 for 循环中迭代数组(array).切片(slice).通道(channel)或集合(map)的元素.在数组和切片中它返回元素的索 ...

  5. 【解决】MySQL提示启动成功,实际进程并没有起来

    一.概括: 1.查看运行日志 vim /var/log/mariadb/mariadb.log 2.修改配置文件 vim /etc/my.cnf 3.修改文件权限 chown mysql.mysql ...

  6. 【UR #5】怎样更有力气

    Problem Description 大力水手问禅师:"大师,很多事情都需要用很大力气才能完成,而我在吃了菠菜之后力气很大,于是就导致我现在非常依赖菠菜.我很讨厌我的现状,有没有办法少吃点 ...

  7. requests-html库render的使用

    一.render的使用 from requests_html import HTMLSession session =HTMLSession() response = session.get('htt ...

  8. SSM框架之Spring(3)IOC及依赖注入(基于注解的实现)

    Spring(3)IOC及依赖注入(基于注解的实现) 学习基于注解的 IoC 配置,大家脑海里首先得有一个认知,即注解配置和 xml 配置要实现的功能都是一样 的,都是要降低程序间的耦合.只是配置的形 ...

  9. JavaScript基础6

    计时器 setInterval()   按照指定周期来调用函数或计算表达式     以毫秒计算 语法    setInterval(code,millisec[,“lang”]) code 要调用的函 ...

  10. How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1)

    How to recover a skipped tablespace after an incomplete recovery? (Doc ID 1561645.1) APPLIES TO: Ora ...