views:

3649

answers:

4

Is it possible to do mysqldump by single SQL query?

I mean tu dump the whole database, like phpmyadmin does when you do export to SQL

+1  A: 

not mysqldump, but mysql cli...

mysql -e "select * from myTable" -u myuser -pxxxxxxxxx mydatabase

you can redirect it out to a file if you want :

mysql -e "select * from myTable" -u myuser -pxxxxxxxxx mydatabase > mydumpfile.txt

Zak
You can use the -B (--batch) switch to output as tab delimited, too.
jonstjohn
What if I want it in a format that allows reinsertion?
Thomas Ahle
what do you mean thomas? maybe you should post a question that is more specific...
Zak
+8  A: 

This should work

mysqldump --databases X --tables Y --where="1 limit 1000000"
Thomas Ahle
+1 Very helpful, Thank you!
BigJoe714
+1  A: 

You can dump a query as csv like this:

SELECT * from myTable INTO OUTFILE 'querydump.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'

Guy
A: 

Zak, how can i restore that data using mysql?

Spartacus