mysqldump with multiple tables with or without where clause

前端 未结 2 1493
清歌不尽
清歌不尽 2020-12-14 22:53

I have a set of tables in my database that I have to take a dump ( :D ) of. My problem is I want to take some data from some tables that only date back certain days and woul

2条回答
  •  星月不相逢
    2020-12-14 23:23

    So the solution above won't work unless the tables have a common foreign key field.

    If you look at my example below, the user_addresses, user_groups, and user_payment_methods all have the user_id field i common. When mysqldump executes the where clause it will filter those tables.

    mysqldump -u  -p  
    user_addresses user_groups user_payment_methods 
    -w "user_id 
    in (select id from users where email like '%@domain.com')"
    --single-transaction| gzip > sqldump.sql.gz
    

提交回复
热议问题