Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DBUSER=user
  4. DBPASSWORD=pwd
  5. DBSNAME=sourceDb
  6. DBNAME=destinationDb
  7. DBSERVER=localhost
  8.  
  9. fCreateTable=""
  10. fInsertData=""
  11. echo "Copying database ... (may take a while ...)"
  12. DBCONN="-h ${DBSERVER} -u ${DBUSER} --password=${DBPASSWORD}"
  13. echo "DROP DATABASE IF EXISTS ${DBNAME}" | mysql ${DBCONN}
  14. echo "CREATE DATABASE ${DBNAME}" | mysql ${DBCONN}
  15. for TABLE in `echo "SHOW TABLES" | mysql $DBCONN $DBSNAME | tail -n +2`; do
  16. createTable=`echo "SHOW CREATE TABLE ${TABLE}"|mysql -B -r $DBCONN $DBSNAME|tail -n +2|cut -f 2-`
  17. fCreateTable="${fCreateTable} ; ${createTable}"
  18. insertData="INSERT INTO ${DBNAME}.${TABLE} SELECT * FROM ${DBSNAME}.${TABLE}"
  19. fInsertData="${fInsertData} ; ${insertData}"
  20. done;
  21. echo "set foreign_key_checks = 0; $fCreateTable ; $fInsertData ; set foreign_key_checks = 1;" | mysql $DBCONN $DBNAME
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement