I know that to take database dump I can ignore some tables. but I want to take the dump of all table with some percentage of data like 20% 40% because the whole dump is too big. here is my normal dump query.
mysqldump -h dburl -u user -p password --databases dbname > dbname.sql
I am not looking for specific OS and using Linux Ubuntu.
To dump entire databases, do not name any tables following db_name , or use the --databases or --all-databases option. To see a list of the options your version of mysqldump supports, issue the command mysqldump --help .
It took a total of 1 minute 27 seconds to take a dump of the entire database (same data as used for mysqldump) and also it shows its progress which will be really helpful to know how much of the backup has completed.
The 80-20 rule says that the smallest 80% of the tables will probably consume only 20% of the space. So have one mysqldump for them.
Then have more mysqldump(s) for each remaining table smaller than 20% of the space.
Finally, any big tables need the --where
option mentioned by Nambu14. Or you could try the kludge of saying --where="true LIMIT 20000,10000"
to sneak an OFFSET
and LIMIT
in. (See one of the comments on https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html ) But do not allow writes to the table while doing that -- it could lead to extra/missing records.
Or you could adapt chunking techniques as discussed here . This avoids the extra/missing problem and avoids the LIMIT
kludge. With luck, you can hard code the range values needed for ranges like this --where="my_pk >= 'def' AND my_pk < 'mno'"
Don't forget to deal with Triggers, Stored routine, Views, etc.
There's a similar question open. With the --where option you can limit the amount of records included in the mysqldump (official documentation here), but this option applies for every table in the database.
Another way is to give the command a sql script to run and prepare the data in that script, this will work as a pseudo ETL pipeline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With