我可以创建带有show关键字的MySQL视图吗?

00jrzges  于 2022-12-10  发布在  Mysql
关注(0)|答案(1)|浏览(146)

我需要创建这样的视图

create view GetProcessList
 as
 show processlist

有可能吗?

sqxo8psd

sqxo8psd1#

有可能吗?
否,您只能基于SELECT语句创建视图,而不能基于SHOW语句创建。但是,如果您的问题真的是如何像访问一个表一样访问进程列表……那么在INFORMATION_SCHEMA元数据库中就已经有了:

MariaDB [information_schema]> SELECT * FROM information_schema.PROCESSLIST;
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
| ID | USER | HOST      | DB                 | COMMAND | TIME | STATE                | INFO                                         | TIME_MS | STAGE | MAX_STAGE | PROGRESS | MEMORY_USED | EXAMINED_ROWS | QUERY_ID |
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
| 42 | root | localhost | information_schema | Query   |    0 | Filling schema table | SELECT * FROM information_schema.PROCESSLIST |   0.561 |     0 |         0 |    0.000 |       83104 |             0 |      204 |
+----+------+-----------+--------------------+---------+------+----------------------+----------------------------------------------+---------+-------+-----------+----------+-------------+---------------+----------+
1 row in set (0.00 sec)

相关问题