How to say create procedure if not exists in MySQL

Frank picture Frank · Mar 30, 2012 · Viewed 34.8k times · Source

I am trying to create a procedure in a MySQL database, but I want to check if it exists first.

I know how to do it for a table but when I use the same syntax for a stored procedure it doesn't compile.

Does anybody know?

Answer

Cory Klein picture Cory Klein · Jun 10, 2015

Just drop the procedure if it does exist and then re-add it:

DROP PROCEDURE IF EXISTS my_procedure;
CREATE PROCEDURE my_procedure()