I recently decided to switch the company through which i get my hosting, so to move my old db into my new db, i have been trying to run this:
mysqldump --host=ipaddress --user=username --password=password db_name table_name | mysql -u username -ppassword -h new_url new_db_name
and this seemed to be working fine.. but because my database is so freaking massive, i would get time out errors in the middle of my tables. So i was wondering if there was any easy way to do a mysqldump
on just part of my table.
I would assume the work flow will look something like this:
create temp_table
move rows from old_table where id>2,500,000 into temp_table
some how dump the temp table into the new db's table (which has the same name as old_table)
but i'm not exactly sure how to do those steps.
Add this --where="id>2500000"
at the end of mysqldump
command. MySQL 5.1 Reference Manual
In your case the mysqldump
command would look like
mysqldump --host=ipaddress \
--user=username \
--password=password \
db_name table_name \
--where="id>2500000
If you dump twice. The second dump will contain table creation info. But next time you want to add the new rows only. So for second dump add --no-create-info
option in mysqldump
command line.
I've developed a tool for this job. It's called mysqlsuperdump and can be found here:
https://github.com/hgfischer/mysqlsuperdump
With it you can speciffy the full "WHERE" clause for each table, so it's possible to specify different rules for each table.
You can also replace the values of each column by each table in the dump. This is useful, for example, when you want to export a database dump to use in development environment.
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