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


当前回答

我的偏好是:

列出了函数和过程, 让我知道哪个是哪个, 只给出过程的名称和类型, 根据当前数据库而不是当前定义器筛选结果 对结果进行排序

把这篇文章中的其他答案拼接在一起,我最终得到了

select 
  name, type 
from 
  mysql.proc 
where 
  db = database() 
order by 
  type, name;

... 最终你会得到这样的结果:

mysql> select name, type from mysql.proc where db = database() order by type, name;
+------------------------------+-----------+
| name                         | type      |
+------------------------------+-----------+
| get_oldest_to_scan           | FUNCTION  |
| get_language_prevalence      | PROCEDURE |
| get_top_repos_by_user        | PROCEDURE |
| get_user_language_prevalence | PROCEDURE |
+------------------------------+-----------+
4 rows in set (0.30 sec)

其他回答

只展示你的:

SELECT
  db, type, specific_name, param_list, returns
FROM
  mysql.proc
WHERE
  definer LIKE
  CONCAT('%', CONCAT((SUBSTRING_INDEX((SELECT user()), '@', 1)), '%'));
SHOW PROCEDURE STATUS;
SHOW FUNCTION STATUS;
SELECT specific_name FROM `information_schema`.`ROUTINES` WHERE routine_schema='database_name'

选择:

SELECT * FROM INFORMATION_SCHEMA.ROUTINES

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';