It is not always that in a project you can use library as yaml_db or seed_fu. Sometimes you just want to move a database from this server to another server. And ofcourse, use mysqldump
will be faster.
First, you my want to connect to remote server via ssh and private key:
sudo ssh -i path_to_your_key remote_user_name@remote_server_address
Dump database:
## Dump all tables of database mysqldump -h database_host -u database_user_name -p database_name > my_db_dump.sql ## Dump some tables of database mysqldump -h database_host -u database_user_name -p database_name table_1 table_2 table_3 > db_part_1_dump.sql ## Dump database ignore some mysqldump -h database_host -u database_user_name -p database_name --ignore-table=my_database.table1 my_database.table2 > db_part_1_dump.sql
Restore database:
mysql -u db_user_name databse_name -p -h host_name < path_to_sql_dump_file
If you need to copy file from your remote server to local computer, use this
sudo scp -i path_to_private_ssh_key remote_user@remote_host:path_to_dump_db_file_on_remote path_to_where_you_want_to_store_on_local ## Or reverse way sudo scp -i path_to_private_ssh_key path_to_where_you_want_to_store_on_local remote_user@remote_host:path_to_dump_db_file_on_remote
You may need some options like these in dump command:
–skip-add-drop-table –no-create-info
–where=”id > 1234567890″
reference this: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html