- FIELDS TERMINATED BY 'value': sets the separator character between fields, which can be a single or multiple characters, and by default is a tab (\t).
- FIELDS [OPTIONALLY] ENCLOSED BY 'value': set the enclosing character of the field, it can only be a single character, if the OPTIONALLY keyword is used, only character data fields such as CHAR and VERCHAR are enclosed.
- FIELDS ESCAPED BY 'value': set how to write or read special characters, can only be a single character, that is, set the escape character, the default value is "\".
- LINES STARTING BY 'value': set the character at the beginning of each line of data, can be single or multiple characters, by default no character is used.
- LINES TERMINATED BY 'value': set the character at the end of each line of data, can be a single or multiple characters, the default value is "\n".
Both the FIELDS and LINES clauses are self-selecting, but if both are specified, FIELDS must precede LINES.
Using the SELECT.... ...INTO OUTFILE statement to dump a table to the server very quickly. If you want to create a result file on some client host other than the server host, you cannot use the SELECT... INTO OUTFILE statement. . INTO OUTFILE, you should use "MySQL -e "SELECT ..." MySQL -e "SELECT ..." > file_name" should be used to generate the file.
SELECT... .INTO OUTFILE is the complement of LOAD DATA INFILE, and the syntax used for the OPTIONS portion of the statement includes some of the FIELDS and LINES clauses that are used in conjunction with the LOAD DATA INFILE statement.
[Example 11.10] Use SELECT.... ...INTO OUTFILE to export records from the person table in the test_db database to a text file, the SQL statement is as follows:
The command to query the specified directory is as follows:
After restarting the MySQL server, use SELECT... again. ...INTO OUTFILE to export the records from the person table in the test_db database to a text file with the following SQL statement:
[Example 11.11] Use the SELECT.... .INTO OUTFILE statement to export the records in the test_db database person table to a text file, using the FIELDS option and the LINES option, requiring that fields be separated by commas, that all field values be enclosed in double quotes, and defining the escape character as a single quote "\'". The SQL statement is as follows:
"FIELDS TERMINATED BY ','" means that fields are separated by commas; "ENCLOSED BY '\"'" means that each field is caused by double quotes;" ESCAPED BY '\'" means that the system's default escape character is replaced by single quotes; "LINES TERMINATED BY '\r\n'" means that each line is terminated by a carriage return line feed to ensure that each record occupies one line.
After successful execution, a file is generated under the D drive. Open the file with the following contents:
Example 11.12] Use the SELECT.... .INTO OUTFILE statement to export the records in the test_db database person table to a text file, using the LINES option, requiring that each row of records begin with the string ">" and end with the string "<end>", the SQL statement is as follows. ", the SQL statement is as follows: