Home > database >  Can I create MySQL View with SHOW keywords?
Can I create MySQL View with SHOW keywords?

Time:12-07

I need to create view like

 create view GetProcessList
 as
 show processlist

Is it possible?

CodePudding user response:

Is it possible?

No you can only create a view base on a SELECT statement , not a SHOW statement. But if your question is really how you can access the processlist as if it were a table....then this is already available in the information_schema meta-database:

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)

CodePudding user response:

No, you cannot create a MySQL view using the SHOW keywords. The SHOW keyword is used to display information about databases, tables, and other objects in a MySQL database, but it cannot be used to create a view.

A view in MySQL is a virtual table that is based on a SELECT statement. It does not store data itself, but rather provides a way to query data from one or more tables and view the results as if they were stored in a separate table.

  • Related