Syntax\n------\n\nSELECT ... INTO OUTFILE 'file_name'\n        [CHARACTER SET charset_name]\n        [export_options]\n\nexport_options:\n    [{FIELDS | COLUMNS}\n        [TERMINATED BY 'string']\n        [[OPTIONALLY] ENCLOSED BY 'char']\n        [ESCAPED BY 'char']\n    ]\n    [LINES\n        [STARTING BY 'string']\n        [TERMINATED BY 'string']\n    ]\n\nDescription\n-----------\n\nSELECT INTO OUTFILE writes the resulting rows to a file, and allows the use of column and row terminators to specify a particular output format. The default is to terminate fields with tabs () and lines with newlines ().\n\nThe file must not exist. It cannot be overwritten. A user needs the FILE privilege to run this statement. Also, MariaDB needs permission to write files in the specified location. If the secure_file_priv system variable is set to a non-empty directory name, the file can only be written to that directory.\n\nThe LOAD DATA INFILE statement complements SELECT INTO OUTFILE.\n\nCharacter Sets\n\nThe CHARACTER SET clause specifies the character set in which the results are to be written. Without the clause, no conversion takes place (the binary character set). In this case, if there are multiple character sets, the output will contain these too, and may not easily be able to be reloaded.\n\nIn cases where you have two servers using different character-sets, using SELECT INTO OUTFILE to transfer data from one to the other can have unexpected results. To ensure that MariaDB correctly interprets the escape sequences, use the CHARACTER SET clause on both the SELECT INTO OUTFILE statement and the subsequent LOAD DATA INFILE statement.\n\nExamples\n--------\n\nSELECT customer_id, firstname, surname FROM customer\n  INTO OUTFILE '/exportdata/customers.txt'\n  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'\n  LINES TERMINATED BY '\\n';\n\nURL: https://mariadb.com/docs/server/reference/sql-statements/data-manipulation/selecting-data/select-into-outfile