Solved

mysql - copy database from one place to another (awk/sed)

Posted on 2014-02-26
4
279 Views
Last Modified: 2014-02-27
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
0
Comment
Question by:crazywolf2010
  • 3
4 Comments
 
LVL 1

Expert Comment

by:Archzilon Eshun-Davies
ID: 39890468
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.
0
 

Author Comment

by:crazywolf2010
ID: 39890491
Can I directly pass this to mysql to load data ?

 mysql -p123 -uthesecondary thesecondary < cat <old.sql> | sed -e 's/<this>/<that>/'
0
 
LVL 1

Expert Comment

by:Archzilon Eshun-Davies
ID: 39890560
yes you can, but I'll advice you check first. of course once you've checked and it does what you want, why not.
0
 
LVL 1

Accepted Solution

by:
Archzilon Eshun-Davies earned 500 total points
ID: 39890565
the syntax though would have to be like this to work
cat <old.sql> | sed -e 's/<this>/<that>/' |  mysql -p123 -uthesecondary thesecondary -

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question