MYSQL - How would I Export tables specifying only certain fields?
SELECT A,B,CFROM XINTO OUTFILE 'file name';
You need the FILE privilege to do this, and it won't overwrite files.
INTO OUTFILE
has a bunch of options to it as well, such as FIELDS ENCLOSED BY
, FIELDS ESCAPED BY
, etc... that you may want to look up in the manual.
To produce a CSV file, you would do something like:
SELECT A,B,CINTO OUTFILE '/tmp/result.txt'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n'FROM X;
To load the data back in from the file, use the LOAD DATA INFILE
command with the same options you used to dump it out. For the CSV format above, that would be
LOAD DATA INFILE '/tmp/result.txt'INTO TABLE XFIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'LINES TERMINATED BY '\n';