What is the MySQL command to show the definition of a procedure, similar to sp_helptext in Microsoft SQL Server?
I know that SHOW PROCEDURE STATUS will display the list of the procedures available. I need to see a single procedure's definition.
What is the MySQL command to show the definition of a procedure, similar to sp_helptext in Microsoft SQL Server?
I know that SHOW PROCEDURE STATUS will display the list of the procedures available. I need to see a single procedure's definition.
SHOW CREATE PROCEDURE <name> Returns the text of a previously defined stored procedure that was created using the CREATE PROCEDURE statement. Swap PROCEDURE for FUNCTION for a stored function.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1You can use this:
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'yourdb' AND ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = "procedurename"; mysql.proc returns blobs for param_list, returns, and body... I'm unable to read them... How did you do it?SELECT * FROM information_schema.PARAMETERS WHERE SPECIFIC_SCHEMA='$dbName' AND SPECIFIC_NAME=\"{$row['ROUTINE_NAME']}\" AND NOT PARAMETER_MODE IS NULL ORDER BY ORDINAL_POSITION;SHOW CREATE PROCEDURE proc_name; returns the definition of proc_name
You can use table proc in database mysql:
mysql> SELECT body FROM mysql.proc WHERE db = 'yourdb' AND name = 'procedurename' ; Note that you must have a grant for select to mysql.proc:
mysql> GRANT SELECT ON mysql.proc TO 'youruser'@'yourhost' IDENTIFIED BY 'yourpass' ; something like:
DELIMITER // CREATE PROCEDURE alluser() BEGIN SELECT * FROM users; END // DELIMITER ; than:
SHOW CREATE PROCEDURE alluser gives result:
'alluser', 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER', 'CREATE DEFINER=`root`@`localhost` PROCEDURE `alluser`() BEGIN SELECT * FROM users; END' An alternative quick and hacky solution if you want to get an overview of all the produres there are, or run into the issue of only getting the procedure header shown by SHOW CREATE PROCEDURE:
mysqldump --user=<user> -p --no-data --routines <database> It will export the table descriptions as well, but no data. Works well for sniffing around unknown or forgotten schemas... ;)
You can show the CREATE PROCEDURE statement with the SQL below. *The doc explains the SQL below and \G can show it more clearly and you must select a database when showing the CREATE PROCEDURE statement otherwise there is the error:
SHOW CREATE PROCEDURE <procedure_name>; Or:
SHOW CREATE PROCEDURE <procedure_name>\G Perfect, try it:
SELECT ROUTINE_DEFINITION FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = 'yourdb' AND ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_NAME = "procedurename";