Reputation: 7035
I would like to export the results of a SELECT query as valid SQL INSERTS and import it into another database (some records were accidentally deleted). Normally I would use PHPMyAdmin's Export feature, but PHPMyAdmin is not available on one of the servers. I believe I can use a VIEW and mysqldump but I'm not sure where to start -- I can't find documentation stating how to dump just my view.
Upvotes: 0
Views: 851
Reputation: 5846
just append INTO OUTFILE "filename"
after your query, and you get a file with the content on that server, that you can load into the other server
Upvotes: -1
Reputation: 140763
SELECT *
FROM yourtable
INTO OUTFILE '/tmp/yourData.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
This will output to a file in a csv format. You can also return the data in the type you want.
Upvotes: 0
Reputation: 16441
Well, if you're importing into one table 1:1, you can export it to a CSV file and then import the results.
SELECT * FROM your_table
INTO OUTFILE '/tmp/table.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
Then you can import it manually by doing
load data local infile 'table.csv' into table your_new_table fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(your, field, names)
Upvotes: 2