How can a export data from mysql
to a file csv
with the date and hour of the day. I try this code but I get a error
SELECT *
FROM order
INTO OUTFILE '/tmp/',NOW(),'_orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
here my 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
this is my event work great but im want diferent cvs in every end of the month
CREATE DEFINER = `admin`@`localhost` EVENT `Order`
ON SCHEDULE EVERY1 MONTH STARTS '2018-12-01 00:00:00'
ON COMPLETION NOT PRESERVE ENABLE
COMMENT 'Order save'
DO SELECT *
FROM Order
INTO OUTFILE '/tmp/_orders.csv'
Here the query getting the name with the date but I cant add this one in the event
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`;
Try prepared statement :
In an event (my MySQL accepted the syntax) :