How to streaming export and import MySQL database to other server
Have you ever dumped a database while simultaneously importing it on another machine? It may sound impossible, but it is straightforward with nc (netcat), which streams the data to the destination.
To stream a MySQL export and import to another machine, run mysqldump on the source and mysql on the destination, transferring the data through nc. If that sounds confusing, here is an example.
Example of using netcat (nc) with mysqldump for an online database import
Suppose we want to dump a database and import it on 10.10.10.10 (using port 13360). Run the following commands.
On the machine exporting the database
[root@DB1 ~]# mysqldump -uroot -p DATABASE_NAME |bzip2 -c | nc 10.10.10.10 13360
On the machine importing the database
[root@DB2 ~]# nc -l 13360 |bzip2 -dc | mysql -uroot -p DATABASE_NAME
If it does not run, or the following error appears:
mysqldump: Got errno 32 on write
Check that the firewall allows communication over port 13360.