如何在mysql命令行中看到存储过程或存储函数的列表,如show tables;或显示数据库;命令。


当前回答

显示所有存储过程:

SHOW PROCEDURE STATUS;

显示所有函数:

SHOW FUNCTION STATUS;

显示指定过程的定义:

SHOW CREATE PROCEDURE [PROC_NAME];

显示给定数据库的所有程序:

SHOW PROCEDURE STATUS WHERE Db = '[db_name]';

其他回答

列出所有数据库的用户过程和功能:

SELECT 
    `ROUTINE_SCHEMA` AS `database`
    ,`ROUTINE_TYPE` AS `type`
    ,`SPECIFIC_NAME` AS `name`
    ,`DTD_IDENTIFIER` AS `data_type`
FROM 
    `INFORMATION_SCHEMA`.`ROUTINES`
WHERE
  `definer` LIKE
  CONCAT('%', CONCAT((SUBSTRING_INDEX((SELECT user()), '@', 1)), '%'))
ORDER BY
    `database`
    ,`type`
    ,`name`
;

列出正在使用的数据库的用户程序和功能:

SELECT 
    `ROUTINE_SCHEMA` AS `database`
    ,`ROUTINE_TYPE` AS `type`
    ,`SPECIFIC_NAME` AS `name`
    ,`DTD_IDENTIFIER` AS `data_type`
FROM 
    `INFORMATION_SCHEMA`.`ROUTINES`
WHERE
  `definer` LIKE
  CONCAT('%', CONCAT((SUBSTRING_INDEX((SELECT user()), '@', 1)), '%'))
AND
   `ROUTINE_SCHEMA` = DATABASE()
ORDER BY
    `type`
    ,`name`
;

我最喜欢呈现的程序列表的当前数据库:名称,参数列表,注释

SELECT specific_name AS name, param_list AS params, `comment`
FROM mysql.proc
WHERE db = DATABASE()
AND type = 'PROCEDURE';

为函数添加返回值:

SELECT specific_name AS name, param_list AS params, `returns`, `comment`
FROM mysql.proc
WHERE db = DATABASE()
AND type = 'FUNCTION';

如果要列出当前所选数据库的存储过程,请

SHOW PROCEDURE STATUS WHERE Db = DATABASE();

它将根据当前选择的数据库列出例程

更新 列出数据库中的函数

select * from information_schema.ROUTINES where ROUTINE_SCHEMA="YOUR DATABASE NAME" and ROUTINE_TYPE="FUNCTION";

要在数据库中列出例程/存储过程,

select * from information_schema.ROUTINES where ROUTINE_SCHEMA="YOUR DATABASE NAME" and ROUTINE_TYPE="PROCEDURE";

要列出数据库中的表,

select * from information_schema.TABLES WHERE TABLE_TYPE="BASE TABLE" AND TABLE_SCHEMA="YOUR DATABASE NAME";

要列出数据库中的视图,

方法1:

select * from information_schema.TABLES WHERE TABLE_TYPE="VIEW" AND TABLE_SCHEMA="YOUR DATABASE NAME";

方法2:

select * from information_schema.VIEWS WHERE TABLE_SCHEMA="YOUR DATABASE NAME";

更具体的说法:

SHOW PROCEDURE STATUS 
WHERE Db = DATABASE() AND Type = 'PROCEDURE'

显示所有存储过程:

SHOW PROCEDURE STATUS;

显示所有函数:

SHOW FUNCTION STATUS;

显示指定过程的定义:

SHOW CREATE PROCEDURE [PROC_NAME];

显示给定数据库的所有程序:

SHOW PROCEDURE STATUS WHERE Db = '[db_name]';