SELECT .... INTO OUTFILE в несколько файлов?

Сделать select в CSV файлы по записям - с помощью LIMIT и сортировки. Данных в таблице около 60.000.

запрос:

SELECT a,b,c INTO OUTFILE '/ca.csv' FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n';

реализация:

SET @record_start = 0;
SET @number_of_records_in_table = 0;
SET @max_number_in_file = 1000;

SELECT COUNT(1) INTO @number_of_records_in_table  FROM my_table;

REPEAT
    SET @filename = CONCAT('/ca_', CAST(@record_start AS CHAR) ,'.csv');
SET @s3 = CONCAT('SELECT a,b,c FROM my_table   LIMIT ?,? INTO OUTFILE \'', @filename ,'\' FIELDS TERMINATED BY \';\' LINES TERMINATED BY \'\n\';');
    PREPARE stmt3 FROM @s3 USING @record_start, @max_number_in_file;
    EXECUTE stmt3;

    SET @record_start = @record_start + @max_number_in_file;
UNTIL @number_of_records_in_table<@record_start
END REPEAT;