Link to home
Start Free TrialLog in
Avatar of crazywolf2010
crazywolf2010Flag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of Archzilon Eshun-Davies
Archzilon Eshun-Davies
Flag of Ghana image

Use
cat <old.sql> | sed -e 's/<this>/<that>/' > <new.sql>

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.
Avatar of crazywolf2010

ASKER

Can I directly pass this to mysql to load data ?

 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
Avatar of Archzilon Eshun-Davies
Archzilon Eshun-Davies
Flag of Ghana image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial