Script To Copy Data From One Database To Another Database
Shell Script To Copy Data From One DB1 To Another DB2 On Other Remote Server #!/bin/bash #Script to Get Number of rows from one DB And Inserting Data into another DB _DB_HOST1=192.168.1.1 _DB_USER1=abc _DB_PASSWORD1=abc _DB_NAME1=db1 _DB_HOST2=192.145.3.2 _DB_USER2=xyz _DB_PASSWORD2=xyz _DB_NAME2=db2 echo "Going to Get Data From DB 1............." mysql -u$_DB_USER1 -p$_DB_PASSWORD1 -h$_DB_HOST1 $_DB_NAME1 -se "select name,age from table1" | while read name age ; do echo "Name = $name Age=$age" echo "Going to Insert Into DB2 From DB! ......." QUERY="Insert into table2(name,age) values('$name','$age')" mysql -u$_DB_USER2-p$_DB_PASSWORD2-h$_DB_HOST2$_DB_NAME2 -se "$QUERY" done exit