Parent table : p_id, t_id, name , salary
Child table : c_id, t_id , age
key : Child.t_id=Parent.t_id
While taking backup i would like to take pull only the matching records from Child table . How can i do it via bash script ?
Thanks in advance .
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
Assuming MySQL 5.x
mysqldump has a
--where option that can be used to limit/select rows to be backed up.
There isn't an option to join two tables using
--where but you can identify which
t_id values you want to backup and then run two mysqldumps as follows:
mysqldump -u... -p... --where="t_id in (10,100,200,300,.....)" database_name parent_table > parent.sql
mysqldump -u... -p... --where="t_id in (10,100,200,300,.....)" database_name child_table > child.sql
Once you have the
child.sql dump files, load them into the target database and you should be good to go.
Also, note that I am assuming
t_id column is indexed on both tables otherwise it may take a long time to dump the rows if the two tables have large number of rows.