Advertisement
fduran

Copy MySQL database into new one

Aug 18th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # Copy / Migrate MySQL database 'olddb' into new one 'newdb'
  2. # 'user' is admin user. 'olduser' and 'newuser' are the users of olddb and newdb schemas
  3. # www.fduran.com
  4.  
  5. # dump olddb
  6. mysqldump --compress -u user -pPassword -h db.example.com --skip-quote-names --databases olddb > olddb.dump
  7.  
  8. # dump stored procedures too
  9. mysqldump --compress -u user -pPassword -h db.example.com --routines --no-create-info --no-data --no-create-db --skip-opt olddb > olddb_routines.dump
  10.  
  11. # create new user and permissions if needed
  12. CREATE USER 'newuser' IDENTIFIED BY 'newPAssword';
  13. GRANT ALL ON `newdb`.* TO 'newuser'@'%';
  14.  
  15. - replace in both dumps olddb -> newdb , olduser -> newuser
  16. - take out DEFINER from dumps:
  17. perl -p -i.bak -e "s/DEFINER=\`\w.*\`@\`\d[0-3].*[0-3]\`//g" olddb_routines.dump
  18. - add USE newdb; on top of routines dump
  19.  
  20. # create new db
  21. cp olddb.dump olddb.sql
  22. cp olddb_routines.dump olddb_routines_routines.sql
  23.  
  24. mysql -u user -pPassword -h db.example.com < olddb.sql
  25. mysql -u user -pPassword -h db.example.com < olddb_routines_routines.sql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement