您可以将 sys 模式设置为默认模式,这样引用其对象时就不需要使用模式名称:You can make the sys schema the
default schema so that references to its objects need not be
qualified with the schema name:
mysql>USE sys;Database changed mysql>SELECT * FROM version;+-------------+---------------+ | sys_version | mysql_version | +-------------+---------------+ | 2.1.1 | 8.4.0-tr | +-------------+---------------+
(version 视图显示 sys 架构和 MySQL 服务器版本。)(The version view shows the
sys schema and MySQL server
versions.)
To access sys schema objects while a
different schema is the default (or simply to be explicit),
qualify object references with the schema name:
mysql> SELECT * FROM sys.version;
+-------------+---------------+
| sys_version | mysql_version |
+-------------+---------------+
| 2.1.1 | 8.4.0-tr |
+-------------+---------------+
sys 模式包含许多以各种方式汇总性能模式表的视图。大多数这些视图都是成对出现的,其中一个成员的名称与另一个成员相同,只是在前面加上 x$ 前缀。例如,host_summary_by_file_io 视图汇总按主机分组的文件 I/O,并将延迟从皮秒转换为更易读的数值(带单位);The sys schema contains many views that
summarize Performance Schema tables in various ways. Most of these
views come in pairs, such that one member of the pair has the same
name as the other member, plus a x$ prefix. For
example, the host_summary_by_file_io
view summarizes file I/O grouped by host and displays latencies
converted from picoseconds to more readable values (with units);
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 视图汇总相同的数据,但显示未格式化的皮秒延迟:The x$host_summary_by_file_io view
summarizes the same data but displays unformatted picosecond
latencies:
mysql> SELECT * FROM sys.x$host_summary_by_file_io;
+------------+-------+---------------+
| host | ios | io_latency |
+------------+-------+---------------+
| localhost | 67574 | 5380678125144 |
| background | 3474 | 4758696829416 |
+------------+-------+---------------+
没有 x$ 前缀的视图旨在提供更用户友好、易于人类阅读的输出。带有 x$ 前缀并以原始形式显示相同值的视图则更多用于其他对数据进行自身处理的工具。有关非 x$ 视图与 x$ 视图之间差异的更多信息,请参见 第 30.4.3 节,“sys 架构视图”。The view without the x$ prefix is intended to
provide output that is more user friendly and easier for humans to
read. The view with the x$ prefix that displays
the same values in raw form is intended more for use with other
tools that perform their own processing on the data. For
additional information about the differences between
non-x$ and x$ views, see
Section 30.4.3, “sys Schema Views”.
要检查 sys 架构对象定义,请使用相应的 SHOW 语句或 INFORMATION_SCHEMA 查询。例如,要检查 session 视图和 format_bytes() 函数的定义,请使用以下语句:To examine sys schema object
definitions, use the appropriate
SHOW statement or
INFORMATION_SCHEMA query. For
example, to examine the definitions of the
session view and
format_bytes() function, use these
statements:
mysql>SHOW CREATE VIEW sys.session;mysql>SHOW CREATE FUNCTION sys.format_bytes;
然而,这些语句显示的定义格式相对不规范。要以更易读的格式查看对象定义,请访问 MySQL 源代码分发版中 scripts/sys_schema 目录下的各个 .sql 文件。However, those statements display the definitions in relatively
unformatted form. To view object definitions with more readable
formatting, access the individual .sql files
found under the scripts/sys_schema directory
in MySQL source distributions.
mysqldump 默认不会导出 sys 模式。要生成转储文件,可在命令行中显式指定 sys 模式,使用以下任一命令:mysqldump does not dump the
sys schema by default. To generate a
dump file, name the sys schema
explicitly on the command line using either of these commands:
mysqldump --databases --routines sys > sys_dump.sql
要从转储文件重新安装模式,请使用以下命令:To reinstall the schema from the dump file, use this command:
mysql < sys_dump.sql