Howto transfer a single mysql table between several deployment stages

Updated . Posted . Visible to the public.

Example task: Multiply the table holidays between several stages.

  1. Open two terminals:

    shell-for stage_1
    shell-for stage_2
    
  2. Get the stage1 and stage2 MySQL credentials:

    cat /opt/www/the_stage.host.tld/current/config/database.yml
    cat config/database.yml # should do it
    
  3. Dump the table to a path reachable by the stage2 user (e.g. home):

    mysqldump -h mysql1 -u stage_1_user -p stage_1_database table_name > ~/table_name_dump.mysql # Select certain records using --where "some_id > 666"
    

    (-h stands for hostname and it is in deed 'mysql1')

  4. Import the dump:

    mysql -h mysql1 -u stage_2_user -p stage_2_database < /home/stage_1_user/table_name_dump.mysql # attention to stage1 and stage2
    

Note that importing a table overwrites an existing table. There won't be a magic merge.

Martin Straub
Last edit
Keywords
backup, dump, restore
License
Source code in this card is licensed under the MIT License.
Posted by Martin Straub to makandra dev (2012-09-27 10:13)