mysqldump from a query

16,965

Solution 1

mysqldump has a --where parameter: Manual

Dump only rows selected by the given WHERE condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

Examples:

--where="user='jimf'"

-w"userid>1"

-w"userid<1"

I don't know what they use, but phpMyAdmin can do this too, Just make the query, select all rows and choose the "export" button to the bottom.

Solution 2

Another option is to insert your query results into a tmp table, then dump that tmp table.

Share:
16,965
Hulk
Author by

Hulk

Updated on June 04, 2022

Comments

  • Hulk
    Hulk almost 2 years

    How can I make a mysql dump for table from a query?

    I need something like this..

    mysqldump -uroot -pxxxx mydb "select * from table where name='1';" >  /tmp/a
    

    Thanks.

  • pedromanoel
    pedromanoel about 10 years
    This solution is better because you can export the result of queries with joins. Mysql can create a table from a select (dev.mysql.com/doc/refman/5.0/en/create-table-select.html)