To export MySQL query results as CSV, you will typically use PHP to connect to MySQL to execute the query, and then export the returned query results using PHP to generate CSV format.
But this is more troublesome, requires the server to install PHP can be implemented.
export CSV method directly using MySQL
We can use the into OutFile, the fields terminated by, the optionally enclosed by, the line terminated by statement to implement the export CSV
the format and function of the statement
into outfile ' exported directory and filename '
Specify the exported directory and file name
Fields terminated by ' Inter-field separator '
To define separators between fields
Optionally enclosed by ' field bracketing '
Define the character that surrounds the field (invalid numeric field)
Lines terminated by ' inline separators '
Define delimiters for each row
Example:
Mysql-u root use test;select * Span style= "color: #000088; Box-sizing:border-box; " >from table into outfile '/tmp/table.csv ' fields Terminated by ', ' optionally enclosed by lines terminated ' \ r \ n ' ;
After execution, the recorded data in the Talbe is exported to the/tmp/table.csv file. Each field is delimited by, and the contents of the field are "surrounded by strings, with each record using \ r \ n line-wrapping."
Export MySQL query results to CSV