-- Mysql version should be >= 5.
-- Have to set system parameters. This means putting the recursion count limit.
SET @@GLOBAL.max_sp_recursion_depth = 255;
SET @@session.max_sp_recursion_depth = 255;
-- change thread_stack size in in.cnf file
thread_stack = 64M
or
thread_stack = 128M
Recursion Procedure
DELIMITER $$
CREATE PROCEDURE samp()
BEGIN
SET @@GLOBAL.max_sp_recursion_depth = 255;
SET @@session.max_sp_recursion_depth = 255;
-- statements
CALL samp();
END
$$