mysqldump partial database

半世苍凉 提交于 2019-12-06 02:26:23

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8914887/mysqldump-partial-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!