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


当前回答

Praveenkumar_V帖子的一个变种:

SELECT `name` FROM mysql.proc WHERE db = 'dbname' AND `type` = 'PROCEDURE';
SELECT `name` FROM mysql.proc WHERE db = 'dbname' AND `type` = 'FUNCTION';

..这是因为我在做家务之后需要节省时间:

SELECT CONCAT(
     "GRANT EXECUTE ON PROCEDURE `"
    ,`name`
    ,"` TO username@'%'; -- "
    ,`comment`
)
FROM mysql.proc
WHERE db = 'dbname'
AND `type` = 'PROCEDURE';

SELECT CONCAT(
     "GRANT EXECUTE ON FUNCTION `"
    ,`name`
    ,"` TO username@'%'; -- "
    ,`comment`
)
FROM mysql.proc
WHERE db = 'dbname'
AND `type` = 'FUNCTION';

其他回答

对所有过程使用以下查询:

select * from sysobjects 
where type='p'
order by crdate desc

更具体的说法:

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

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

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;

如上所述,

show procedure status;

确实会显示过程列表,但会显示服务器范围内的所有过程。

如果你想只看到一个数据库中的那些,试试这个:

SHOW PROCEDURE STATUS WHERE Db = 'databasename';