如何在mysql命令行中查看存储过程或存储函数的列表,如show tables;
或show databases;
命令。
答案 0 :(得分:705)
SHOW PROCEDURE STATUS;
SHOW FUNCTION STATUS;
答案 1 :(得分:204)
show procedure status
将显示存储过程。
show create procedure MY_PROC
将显示过程的定义。和
help show
将显示show
命令的所有可用选项。
答案 2 :(得分:83)
以名义方式查看程序
select name from mysql.proc
下面用于列出所有程序的代码,下面的代码与show procedure status
给出相同的结果select * from mysql.proc
答案 3 :(得分:42)
更具体的方式:
SHOW PROCEDURE STATUS
WHERE Db = DATABASE() AND Type = 'PROCEDURE'
答案 4 :(得分:30)
如上所述,
show procedure status;
确实会显示一个程序列表,但会在服务器范围内显示所有。
如果您只想查看单个数据库中的那些,请尝试以下方法:
SHOW PROCEDURE STATUS WHERE Db = 'databasename';
答案 5 :(得分:26)
替代:
SELECT * FROM INFORMATION_SCHEMA.ROUTINES
答案 6 :(得分:21)
我的偏好是:
从这个帖子中的其他答案拼凑而成,我最终得到了
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)
...最终会得到如下结果:
{{1}}
答案 7 :(得分:14)
使用它:
SHOW PROCEDURE STATUS;
答案 8 :(得分:9)
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';
答案 9 :(得分:8)
只展示你的:
SELECT
db, type, specific_name, param_list, returns
FROM
mysql.proc
WHERE
definer LIKE
CONCAT('%', CONCAT((SUBSTRING_INDEX((SELECT user()), '@', 1)), '%'));
答案 10 :(得分:7)
SELECT specific_name FROM `information_schema`.`ROUTINES` WHERE routine_schema='database_name'
答案 11 :(得分:5)
如果要列出当前所选数据库的存储过程,
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";
列出数据库中的表格,
select * from information_schema.TABLES WHERE TABLE_TYPE="VIEW" AND TABLE_SCHEMA="YOUR DATABASE NAME";
列出数据库中的视图,
方法1:
select * from information_schema.VIEWS WHERE TABLE_SCHEMA="YOUR DATABASE NAME";
方法2:
{{1}}
答案 12 :(得分:5)
SHOW PROCEDURE STATUS;
显示所有存储过程。
SHOW FUNCTION STATUS;
显示所有功能。
SHOW CREATE PROCEDURE [PROC_NAME];
将显示指定程序的定义。
SHOW PROCEDURE STATUS WHERE Db = '[db_name]';
将显示给定数据库的所有过程。
答案 13 :(得分:1)
show procedure status;
使用此命令可以查看数据库中的所有过程
答案 14 :(得分:0)
MySQL8
列出所有数据库的用户程序和功能:
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`
;
答案 15 :(得分:0)
DELIMITER $$ DROP PROCEDURE IF EXISTS 'sp_radacct_montly_backup' $$
CREATE PROCEDURE 'sp_radacct_montly_backup'()
BEGIN
DECLARE radacct_pmonth varchar(100);
DECLARE excessao SMALLINT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET excessao = 1;
DECLARE radacct_pmonth varchar(100);
SET raddacct_pmonth:=(SELECT CONCAT('radacct_',YEAR(NOW()), MONTH (NOW())-1 AS radacct_pmonth);
START TRANSACTION
CREATE TABLE IF NOT EXISTS radacct_pmonth;
IF excessao = 1
THEN
SELECT 'Erro ao criar copia da tabela raddacct' As Msg;
ROLLBACK;
ELSE
DELETE FROM radius.radacct WHERE acctstoptime < date_sub(NOW(), INTERVAL 1 MONTH);
IF excessao = 1
THEN
SELECT 'Erro ao remover registros com mais de um mes' AS Msg; ROLLBACK;
ELSE
COMMIT;
END IF;
END IF;
END $$ DELIMITER;
MariaDB [radius]> SHOW PROCEDURE STATUS;
->
如果在创建过程后未返回任何错误消息,为什么当我要求列出时,锁定命令并且不退出'->'?
答案 16 :(得分:0)
我最喜欢的当前数据库程序列表的呈现方式:名称,参数列表,注释
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';
答案 17 :(得分:0)
从MySQL 8.0开始,mysql.procs
表已被删除。从此处的答案中使用此表运行任何命令,都会产生一个错误(逻辑上很正确):
Table 'mysql.proc' doesn't exist
相反,要仅检索过程/函数名称的列表,请使用:
SELECT specific_name FROM `information_schema`.`ROUTINES` WHERE routine_schema='<your_db_name>';
就我而言,我对其进行了编辑以仅显示过程,而不显示功能:
SELECT specific_name FROM `information_schema`.`ROUTINES` WHERE routine_schema='<your_db_name>' AND routine_type='PROCEDURE';
答案 18 :(得分:-2)
对所有程序使用以下查询:
select * from sysobjects
where type='p'
order by crdate desc