0

我有这个活动

CREATE DEFINER=`frontend`@`%` EVENT `general_log_event` 
ON SCHEDULE EVERY 5 MINUTE STARTS '2013-03-05 16:08:54' DO BEGIN

    SET @query = CONCAT("
    SELECT * INTO OUTFILE '/Users/Admin/logs/log_", 
    DATE_FORMAT(NOW(),"%M-%d-%y_%h-%m-%s"), ".csv'",
    " 
    FIELDS TERMINATED BY ','
    ENCLOSED BY '\"\'",
    "LINES TERMINATED BY '\\n\'",
    "FROM mysql.general_log;");
    PREPARE statement FROM @query;
    EXECUTE statement; 
END

但每次运行它都会给我这个错误

[ERROR] Event Scheduler: [root@%][ge.general_log] File '/Users/Admin/logs/log_03-05-13_04-03-54.csv' already exists

每次都是相同的确切错误。它不应该具有每次都应该更改的相同文件。

4

1 回答 1

0

用于FLOOR(1052 + RAND() * 3564)创建随机值,它似乎正在工作。这是最后一块。

SET @query = CONCAT("
SELECT SQL_NO_CACHE * INTO OUTFILE '/Users/Admin/logs/General_Log/log_", 
DATE_FORMAT(NOW(),"%M-%d-%y_%h-%m-%s_"), FLOOR(1052 + RAND() * 3564), ".csv'",
" 
FIELDS TERMINATED BY ','
ENCLOSED BY '\"\'",
"LINES TERMINATED BY '\\n\'",
"FROM mysql.general_log;");
PREPARE statement FROM @query;
EXECUTE statement;

SELECT @query;
于 2013-03-08T17:20:24.723 回答