I have this 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
but every time it runs it gives me this error
[ERROR] Event Scheduler: [root@%][ge.general_log] File '/Users/Admin/logs/log_03-05-13_04-03-54.csv' already exists
its the same exact error every time. it shouldnt have the same file it should be changing every time.
used FLOOR(1052 + RAND() * 3564)
to create a random value and it seems to be working. Here is the final piece.
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;