crazywolf2010
asked on
mysql - copy database from one place to another (awk/sed)
Hi,
I have database called primary with 400 mysql tables, some triggers.
In theory I should able to carry mysqldump export and then use mysql to import it. And it works partially.
I found problem with triggers, functions . They are tagged as primary database and while compilation it fails as I am compiling it on another database.
For exa
mysql -p123 -utheprimary thesecondary < theprimary_bkup - Worked
But I had to carry within vi
%s/theprimary/thesecondary /g
I need to automate this task thru bash script. I think awk/sed should do the trick.
Thanks
I have database called primary with 400 mysql tables, some triggers.
In theory I should able to carry mysqldump export and then use mysql to import it. And it works partially.
I found problem with triggers, functions . They are tagged as primary database and while compilation it fails as I am compiling it on another database.
For exa
mysql -p123 -utheprimary thesecondary < theprimary_bkup - Worked
But I had to carry within vi
%s/theprimary/thesecondary
I need to automate this task thru bash script. I think awk/sed should do the trick.
Thanks
ASKER
Can I directly pass this to mysql to load data ?
mysql -p123 -uthesecondary thesecondary < cat <old.sql> | sed -e 's/<this>/<that>/'
mysql -p123 -uthesecondary thesecondary < cat <old.sql> | sed -e 's/<this>/<that>/'
yes you can, but I'll advice you check first. of course once you've checked and it does what you want, why not.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
be sure to check your regex in the sed command to properly format for you,
and the check to make sure new.sql is in the format you want.