18

Does anyone know what is the syntax for renaming a mysql stored procedure/function? Or is this even supported in MySQL? I've been googling this for several minutes...

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
  • 1
    This is documented http://forums.mysql.com/read.php?10,274538,274563#msg-274563 here as a workaround. A stored procedure to rename could be found here http://www.youdidwhatwithtsql.com/rename-mysql-stored-procedures/819 . A feature request with submission in 2007 is apparently still open if this http://bugs.mysql.com/bug.php?id=27793 is still valid. – Anthill Nov 30 '12 at 11:59

1 Answers1

27

try this

 UPDATE `mysql`.`proc`
SET name = '<new_proc_name>',
specific_name = '<new_proc_name>'
WHERE db = '<database>' AND
  name = '<old_proc_name>';

Also note: If have granted privileges to users for this procedure you will need to update the procedure name in procs_priv as well.

UPDATE `mysql`.`procs_priv`
SET Routine_name = '<new_proc_name>'
WHERE Db = '<database>' AND
  Routine_name = '<old_proc_name>';
 FLUSH PRIVILEGES;

Source: MySQL Forums :: Newbie :: Rename Stored Procedure Syntax

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
SRIRAM
  • 1,888
  • 2
  • 17
  • 17
  • Do you need any specific privileges to change that table?' – Ferenc Deak Nov 30 '12 at 11:54
  • Is there a variant of this statement where you don't need to specify the database name, just use the active database? – Gruber Aug 08 '13 at 08:09
  • @Gruber, yes – simply use the function `DATABASE()` to get the current database name, at append it as a condition: `UPDATE mysql.proc SET name = ..., specific_name = ... WHERE name = ... AND db = DATABASE()` – crishoj Nov 03 '15 at 09:30
  • Also don't forgot to change caller events of the stored procedure: alter event event_RunSP1 on schedule every 60 second DO call ; – Mohsen Abasi Feb 08 '18 at 07:21