mysql 快速修复所有表错误
2017-08-10 本文已影响6人
totzcc
检查、优化、并修复所有的数据库用:
mysqlcheck -A -o -r -p
快速转换表类型
drop PROCEDURE if EXISTS alter_table_type;
create PROCEDURE alter_table_type()
BEGIN
DECLARE v_sql VARCHAR(500);
DECLARE tb_name VARCHAR(500);
DECLARE all_tables CURSOR for select table_name from information_schema.`TABLES` where information_schema.`TABLES`.TABLE_SCHEMA = '数据库名';
open all_tables;
LOOP
FETCH all_tables into tb_name;
select CONCAT('alter ',tb_name);
set v_sql = concat('ALTER TABLE `',tb_name,'` ENGINE=MyISAM;');
set @v_sql=v_sql;
PREPARE stmt from @v_sql;
EXECUTE stmt;
deallocate prepare stmt;
END LOOP;
close all_tables;
select 'ok';
end;
call alter_table_type();
drop PROCEDURE alter_table_type;