Skip to content

Instantly share code, notes, and snippets.

@ErDmKo
Last active August 29, 2015 14:02
Show Gist options
  • Save ErDmKo/0add3e457590169321b6 to your computer and use it in GitHub Desktop.
Save ErDmKo/0add3e457590169321b6 to your computer and use it in GitHub Desktop.
Change table engine for the all tables in the db
vim
%s/InnoDB/MyISAM/g
g/CONSTRAINT/d
%s/)\,\n)/\)\r\)/g
SET foreign_key_checks = 0;
drop procedure if exists `to_MyISAM`;
CREATE PROCEDURE `to_MyISAM` ()
BEGIN
DECLARE a,c VARCHAR(256);
DECLARE b INT;
DECLARE cur1 CURSOR FOR
select concat(student_surgut.table_name)
from information_schema.tables student_surgut
where `TABLE_TYPE` = 'BASE TABLE'
and table_schema = 'student_surgut';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
DECLARE CONTINUE HANDLER FOR 1061 SET b = 0;
OPEN cur1;
SET b = 0;
WHILE b = 0 DO
FETCH cur1 INTO a;
IF b = 0 THEN
SET @c = concat ('ALTER IGNORE TABLE `', a, '` ENGINE=MyISAM');
SELECT concat('ALTER IGNORE TABLE `', a, '` ENGINE=MyISAM');
PREPARE stmt1 FROM @c;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
END IF;
END WHILE;
CLOSE cur1;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment