patternsqlMinor
Can I mysqldump an entire database while using where='condition' on individual tables?
Viewed 0 times
cantableswhileconditionentireindividualwheremysqldumpdatabaseusing
Problem
I have used mysqldump to dump an entire database,
However, when I want to use
and then reconstructed the database table by table
Is it possible to use the where clause with mysqldump on specific tables when dumping an entire database?
However, when I want to use
--where=condition", on individual tables, I have dumped individual tables mysqldump --where='condition' mydb table > table.sqland then reconstructed the database table by table
for i in *sql; do mysql newdb < i; doneIs it possible to use the where clause with mysqldump on specific tables when dumping an entire database?
Solution
You will have to custom script each table
The
Here is a post I made back in August 15, 2011
Is it possible to mysqldump a subset of a database required to reproduce a query?
Here is an crazy example
Suppose the table is this in the myworld database:
and you want to break it up into two dumps
You will need three files (one for the database schema, and two for the data)
The
--where option is designed to help mysqldump a single tableHere is a post I made back in August 15, 2011
Is it possible to mysqldump a subset of a database required to reproduce a query?
Here is an crazy example
Suppose the table is this in the myworld database:
CREATE TABLE data_for_world
(
id int not auto_increment,
continent varchar(16),
primary key (id)
);
insert into data_world (continent)
values ('Asia'),('Africa'),('Eupore'),
('NorthAmerica'),('SouthAmerica'),
('Australia'),('Antarctica');and you want to break it up into two dumps
- one with continents that start with A
- one with continents that do not start with A
You will need three files (one for the database schema, and two for the data)
mysqldump --no-data --database myworld > myworld_schema.sql
mysqldump --no-create-info myworld data_for_world --where="substr(continent,1,1)='A'" > data1.sql
mysqldump --no-create-info myworld data_for_world --where="substr(continent,1,1)<>'A'" > data2.sqlCode Snippets
CREATE TABLE data_for_world
(
id int not auto_increment,
continent varchar(16),
primary key (id)
);
insert into data_world (continent)
values ('Asia'),('Africa'),('Eupore'),
('NorthAmerica'),('SouthAmerica'),
('Australia'),('Antarctica');mysqldump --no-data --database myworld > myworld_schema.sql
mysqldump --no-create-info myworld data_for_world --where="substr(continent,1,1)='A'" > data1.sql
mysqldump --no-create-info myworld data_for_world --where="substr(continent,1,1)<>'A'" > data2.sqlContext
StackExchange Database Administrators Q#15029, answer score: 3
Revisions (0)
No revisions yet.