Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqldump from a query

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.

like image 556
Hulk Avatar asked Mar 12 '10 10:03

Hulk


People also ask

How use Mysqldump command-line?

To dump/export a MySQL database, execute the following command in the Windows command prompt: mysqldump -u username -p dbname > filename. sql . After entering that command you will be prompted for your password.

How can I get Mysqldump from all databases?

To backup multiple MySQL databases with one command you need to use the --database option followed by the list of databases you want to backup. Each database name must be separated by space. The command above will create a dump file containing both databases.

What is the output of Mysqldump?

It dumps one or more MySQL databases for backup or transfer to another SQL server. The mysqldump command can also generate output in CSV, other delimited text, or XML format.


1 Answers

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.

like image 90
Pekka Avatar answered Nov 16 '22 03:11

Pekka