How can data from mysql
be exported to a file cvs
with date and time of day? I try this code but I get an error. I'm trying to do a evento
My Event
CREATE DEFINER = 'admin'@'localhost' EVENT 'Respaldo Ordenes'
ON SCHEDULE EVERY1 MONTH STARTS '2018-12-01 00:00:00'
ON COMPLETION NOT PRESERVE ENABLE
COMMENT 'Respaldo de Ordenes cada fin de mes'
DO SELECT *
FROM Order
INTO OUTFILE '/tmp/_orders.csv'
But I want to add the date so that it does not duplicate with the same name
SELECT *
FROM order
INTO OUTFILE '/tmp/',NOW(),'_orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
error
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' ,NOW(), '"'_orders.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TER' at line 3
Investigating I found this code
SET @'outfull' := CONCAT('/tmp/', NOW(), 'orders.csv');
SET @'qry' := CONCAT('SELECT *
INTO OUTFILE \'', @'outfull', '\'
FIELDS TERMINATED BY \';\'
ENCLOSED BY \'"\'
LINES TERMINATED BY \'\n\'
FROM 'order'');
PREPARE 'stmt' FROM @'qry';
SET @'qry' := NULL;
EXECUTE 'stmt';
DEALLOCATE PREPARE 'stmt';