MYSQL - How would I Export tables specifying only certain fields? MYSQL - How would I Export tables specifying only certain fields? database database

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';


If you are using phpMyAdmin,

Run the query

SELECT A,B,C FROM X

and there is an export option in the bottom of the result.


OUTFILE doesn't produce you a SQL dump, neither mysqldump can operate on subset of columns.But you can create table temp_weeeee select ...., export and drop it.