title: Backup stored procedure only copies one table
body: <p>I´ve been trying to create a stored procedure that will copy my database to another database. The problem is that only the first table is copying. Do you guys see any errors in the code? </p>
  
  <pre><code>     DELIMITER $$
  
       DROP PROCEDURE IF EXISTS fes_backup  $$
  
       CREATE PROCEDURE  do_backup (IN name_bbdd VARCHAR(20), IN new_name_bbdd VARCHAR(20))
       BEGIN
  
          DECLARE done INT DEFAULT 0;
          DECLARE name_table VARCHAR(20);
  
          DECLARE cur1 CURSOR FOR SELECT table_name FROM information_schema.tables
          WHERE table_schema=name_bbdd AND table_type="base table";
  
          DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
  
          OPEN cur1;
  
          bucle: LOOP
  
             FETCH cur1 INTO name_table;
             IF done=1 THEN
                LEAVE bucle;
             END IF;
  
             SELECT CONCAT("Copio ",name_table," a nova base de dades ",new_name_bbdd);
  
             SET @aux = CONCAT("CREATE TABLE ",name_table," LIKE ", name_bbdd, ".", name_table);
             PREPARE stmt1 FROM @aux;
             EXECUTE stmt1;
             DEALLOCATE PREPARE stmt1;
  
             SET @aux = CONCAT("INSERT INTO ",name_table," SELECT * FROM ", name_bbdd, ".", name_table);
             PREPARE stmt1 FROM @aux;
             EXECUTE stmt1;
             DEALLOCATE PREPARE stmt1;
  
          END LOOP bucle;
  
          CLOSE cur1;
  
       END$$
  
       DELIMITER ;
  </code></pre>
  
  <p>Thanks a lot!</p>