views:

123

answers:

1

Is there a way to create a dump/export/save a temporary MySQL table into a file on disk(.sql file that is, similar to one that is created by mysqldump)?

+1  A: 

Sorry, I did not read the question properly the first time around... at any rate, the best I can think of is using the SELECT ... INTO OUTFILE statement, like this:

SELECT * INTO OUTFILE 'result.csv'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM temp_table;

This does have many limitations thought, for instance, it only dumps the raw data without including the field headers. The other thing I found that may or may not be of use is the SHOW CREATE TABLE statement. If you can find some way of combining the output from these two statements, you may be able to get a proper "dump" file as produced by my command below.


You should be able to use the mysqldump application:

mysqldump --databases temptable > file.sql

This will dump the table with CREATE decelerations.

Mike
Temp table only exists within the scope of connection, hence this won't work.
Alex N.
Be aware that SELECT ... INTO OUTFILE requires a specific permission be given to the user.
Charles