It’s not a big deal to perform mysqldump command, get your database as a file and transfer MySQL database to another server by moving the file to another server and import it,
But what if there is no enough space on a disk to store the dump file? In this case it would be great to create MySQL dump file directly on the remote server. And not only you can create dump file directly but even clone a database to remote MySQL! Here I show how to do this.
mysqldump directly to remote mysql clone
Issue the following command:
1 |
mysqldump -uroot dbname | ssh root@remoteserver.com "mysql -D dbname" |
Here we make a pipe and pump the dump directly into mysql on the remote server, essentially cloning the database is one command!
mysqldump directly to remote server in a dump file
Issue the following command:
1 |
mysqldump -uroot -p <dbname> | ssh <user>@<ip_address> "cat > <filename>.sql |
This command will perform mysqldump and the dump file will be created directly on the remote server!
The variation of the above in case we want to initiate mysqldumpon the remote server:
1 |
mysqldump -uroot -p -h 10.10.10.100 <dbname> > <dbname>.sql |
Good luck!