MySQL exporting INTO OUTFILE --secure-file-priv error when using set directory

It is important to use path location mentioned in:

mysql> SELECT @@secure_file_priv;

If you will use customized path location, you will still get this error. As mentioned by Lateralus, don't forget to change path to forward slashes.


This worked for me. It needs double backslash and if you are trying any tools in between to connect to mysql simply add escape chars.

SELECT * 
      INTO OUTFILE 'C:\\\\ProgramData\\\\MySQL\\\\MySQL Server 8.0\\\\Uploads\\\\employees.txt'
        FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
      FROM employees;

Argh. It was a freakin' typo, my \'s should have been /'s

So my query is now this:

SELECT * FROM   mysql.db INTO OUTFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/db_pipe.csv" FIELDS TERMINATED BY '|' ENCLOSED BY '"'  LINES TERMINATED BY '\n';

In my case (Windows):

  1. In my.ini, set secure_file_priv=""

  2. Use double back slash in the path like below:

SELECT description, comment FROM usecase
INTO OUTFILE 'C:\\tmp\\usecase0.csv' 
FIELDS ENCLOSED BY '"' 
TERMINATED BY ';' 
ESCAPED BY '"' 
LINES TERMINATED BY '\r\n';