MySQL : Exporting The Resultset of a Table into CSV File
To export the resultset of a table into a .csv file in MySQL we have to execute the following query.
SELECT * INTO OUTFILE pathName
FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
FROM tableName
Where ‘pathname’ is the path along with the .csv file name and ‘tableName’ is your table. You can also specify specific columns to be exported as .csv file.
|
Example:
SELECT * INTO OUTFILE ‘D://test.csv’
FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
FROM Employees
In the above example,
The result will be saved in the test.csv file in the D drive of the Database Server.
|
0 comments:
Post a Comment