Solved

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

Posted on 2014-02-26
4
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Linux Hosting 16 105
Migrating a Linux server to VMware 3 140
NFS v4 7 76
redirect certain certain urls to a subdomain on a different server 4 41
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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