Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
centos commands 6 88
Linux mount of Windows Shared Now Fails 8 111
UM7 Stop Sending packets with GPS Sensor 1 18
AWS Linux EC2 question on group 7 6
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

713 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