Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

813 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