Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to export some data from MySQL, but not the entire MySQL database. And I'd like the export to be human-readable SQL statements that can recreate the data (i.e. not just an XML or CSV dump).

So I'm looking for something like:

SELECT * FROM mytable WHERE id = 3 INTO OUTFILE 'test'

And I'd like the results to be standard SQL in a text file (which I can then run against a remote database). Ideally, I'd like to specify if it's an INSERT or UPDATE statement in the output file.

This functionality exists in phpMyAdmin but I'd like to have it in my own PHP script so I can automate things a bit. So, can MySQL do this on its own, or do I need to write my own code to manually piece together the export SQL statements?

share|improve this question
1  
phpMyAdmin allows you to script out a table as CSV or SQL, just as you want it. –  user3463 Jul 18 '12 at 0:06
    
OMG I totally forgot to mention the whole point of my post, which is what I'm adding now: "This functionality exists beautifully in phpMyAdmin but I'd like to have it in my own PHP script so I can automate things a bit." (Thank you for the reply, regardless!) –  Eric Jul 18 '12 at 0:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.