![]() ![]() Mysqldump -u -p -t -T/path/to/directory -fields-terminated-by=, Use the following command in a command prompt/terminal:.Here, we will discuss how mysqldump can be used to export a MySQL table to CSV. Moreover, it is also used for backup and recovery. Mysqldump is a utility tool provided by MySQL server that enables users to export tables, databases, and entire servers. Use the following command to do it: SELECT column, column, IFNULL(column, 'NA')įROM tableName INTO OUTFILE 'path-to-file/outputFile.csv' This may lead to confusion and thus, you may want to replace this ‘N’ string with a string like NA (not applicable) that makes more sense. If your results contain NULL values, they will appear as ‘N’ in the exported file instead of NULL. INTO OUTFILE 'path-to-file/outputFile.csv’' Use the following command to add column headers: (SELECT 'columnHeading'. To do this, you must use the UNION statement. It is often convenient to add column headers to the output file to better identify and analyze the data. SET = CONCAT("SELECT * FROM tableName INTO OUTFILE FIELDS ENCLOSED BY '" Use the following command to export to a CSV file, and add a timestamp for the time the file was created: SET = DATE_FORMAT(NOW(),'_%Y_%m_%d_%H_%i_%s') You may want to add a timestamp to the exported file, to do that you must use a MySQL prepared statement. You may additionally use the WHERE clause to use specific conditions and filter the results. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |