Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mysqldump for a portion of a table?

So I can export only a table like this:

mysqldump -u root -p db_name table_name > table_name.sql 

Is there any way to export only a portion of a table with mysqldump? For example, 0 - 1,000,000 rows, 1,000,000 - 2,000,000 rows, etc.

Should I do this with mysqldump or a query?

like image 970
datasn.io Avatar asked Apr 14 '11 03:04

datasn.io


People also ask

How do I export a specific table in MySQL?

Open the MySQL database wizard & select the table you want to export. Right-click on the table name & select the table data export wizard option.

How do you dump the table entries of the database?

The 'mysqldump' command is used to dump databases managed by MySQL. Let's consider three the most useful cases of MySQL database dumping. You can also specify several tables separated by whitespace to dump these tables only.

How do I export just one row in MySQL?

If you want to export only certain rows from a MySQL database using mysqldump , you can select the records using the --where option. It dumps 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.

What is single transaction in Mysqldump?

Mysqldump with Transactions The --single-transaction flag will start a transaction before running. Rather than lock the entire database, this will let mysqldump read the database in the current state at the time of the transaction, making for a consistent data dump.


2 Answers

mysqldump -uroot -p db_name table_name --where='id<1000000' 

or you can use

SELECT * INTO OUTFILE 'data_path.sql' from table where id<100000 
like image 194
neocanable Avatar answered Sep 24 '22 10:09

neocanable


mysqldump --skip-triggers --compact --no-create-info --user=USER --password=PASSWORD -B DATABASE --tables MY_TABLE --where='SOME_COLUMN>=xxxx' > out.sql 
like image 33
noisex Avatar answered Sep 23 '22 10:09

noisex