-
-
Save patrickmaciel/aab061e746dd6d8a659637003b17c930 to your computer and use it in GitHub Desktop.
export query result to csv + using dynamic name variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @outpath = "/var/lib/mysql-files/"; | |
SET @outfile = (SELECT date_format(now(), '%Y%m%d%H%m%S')); | |
SET @outextension = "_products.csv"; | |
SET @csvfinal = ' FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' LINES TERMINATED BY \'\n\''; | |
SELECT CONCAT("your query here INTO OUTFILE ",@outpath,@outfile,@outextension,@csvfinal) | |
INTO @SQL; PREPARE stmt FROM @SQL; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment