MySQL batch-file call flush tables for export -
i use batch-file copy database server1 server2.
step 1: call stored procedure flush tables table1,table2, ..., table1000 export; step 2: copy files .ibd , .cfg temp directory , archive step 3: unlock tables;
the problem first step - files .cfg created , removed, unlock tables not called. why? files .cfg created , disappear, not have time copy
.bat file command:
mysql -u %db_user% -p%db_password% %db_name% --default-character-set=utf8 < stored_proc_flush_tables.sql
file stored_proc_flush_tables.sql:
drop procedure if exists stored_proc_flush_tables; delimiter // create procedure stored_proc_flush_tables ( ) begin declare t_name blob; declare tmp_query blob; declare done_tables int default 0; declare cursor_tables cursor select table_name information_schema.tables table_schema=db_name; declare continue handler not found set done_tables = 1; set @table_name = ''; set @tmp_query = ''; open cursor_tables; tables_loop: loop fetch cursor_tables t_name; if done_tables = 1 leave tables_loop; end if; set @tmp_query = concat_ws('', @tmp_query, ',', t_name); end loop; close cursor_tables; set @tmp_query = trim(leading ',' @tmp_query); set @tmp_query = concat_ws('', 'flush tables', ' ', @tmp_query, ' ', 'for export'); prepare stmt @tmp_query; execute stmt; end // delimiter ; call stored_proc_flush_tables();
files .cfg created , disappear, not have time copy them
problem end mysql session makes flush tables ... export before try copy files.
when mysql session/connection ends locks unlocked , *.cfg consired temporal file deleted.
so should have program makes flush ... export , keeps session open , copies files , after releases table lock (or ends session).
Comments
Post a Comment