用于创建常规日志的Mysql事件错误

时间:2013-03-05 21:38:12

标签: mysql mysql-event

我有这个活动

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

每次都是同样的错误。它不应该有相同的文件,它应该每次都改变。

1 个答案:

答案 0 :(得分: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;