I want to export table data to text file. Is there a way to export results of a query to a file? In other words, if I do a "SELECT * FROM tablename", is there a phrase like "send output to filename.txt", or something?
To export MySQL table data to text file, MySQL provides SELECT INTO OUTFILE statement. Itís used when anyone wants to direct query output to a file. You can use this for your purpose. Take the following example:
SELECT * INTO OUTFILE "C:\\export_data_to_txt_file.txt"
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
Alternatively, you can run mysql command line client with the 'e' flag and redirect standard output to a file:
mysql> -e 'SELECT * FROM test;' > filename.txt;