Solved

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

Posted on 2014-02-26
4
275 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now