LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-14-2005, 01:01 AM   #1
sumitarun
LQ Newbie
 
Registered: Mar 2005
Posts: 8

Rep: Reputation: 0
Question How to compare records in two tables in seperate My Sql database using shell script


I have two My Sql Databases. Initially i copy some records from one of the tables from the first database say 'X' to the table in the second database say 'Y'. Now some else comes and modifies some records form that table in database 'X'. Now suppose both the tables in the database has 1000 records. Now How will i determine which records in the table frm\om the database 'X' are modiifed so that i can copy those records to the secod database 'Y'. Can we use some kind of shell script for this?

Note : There is no columns like date time or flag etc in the tables of the first database 'X' which gets updated in case of modifications.
 
Old 04-14-2005, 02:47 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Quote:
There is no columns like date time or flag etc in the tables of the first database 'X' which gets updated in case of modifications.
So... why not add one?
 
Old 04-14-2005, 02:55 AM   #3
sumitarun
LQ Newbie
 
Registered: Mar 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Cannot add any columns because it is a ERP database in which large chunk of data are being added by the thrid party and they will not modify the structure. And we have to use the same structure while importing the records to our database.
 
Old 04-14-2005, 03:16 AM   #4
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
The easy way: Just copy all the records every time. This is probably good enough solution for a small number of rows like in this case.

The hard way: Dump both tables (sorted) to csv files. Use diff to find differences. Use perl to parse the diff output and generate the SQL statements to update database Y.
 
Old 04-14-2005, 03:57 AM   #5
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Quote:
Cannot add any columns because it is a ERP database in which large chunk of data are being added by the thrid party and they will not modify the structure.
I still don't follow. They don't need to know about a new timestamp column to keep using it exactly as they have, and it would be short work to either add it to your database as well, or strip the timestamp data before inserting or updating. The only way this wouldn't work is if you didn't have administrative control of the database. If that was the case, then this solution also wouldn't work:
You can use mysql's update log to see all insert and update commands on a specific table. Check the documentation for details on that.
 
Old 04-14-2005, 10:45 AM   #6
Robert G. Hays
Member
 
Registered: Jan 2003
Location: Atlanta, Ga., USA
Distribution: Gentoo, Mandrake, ~others
Posts: 157

Rep: Reputation: 30
sumitarun,

I'm guessing that the actual owner of 'X' gave a blanket command that you cannot alter their database in *any* way?

rgh.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 29 09-10-2012 12:29 PM
Restoring *.sql database from Linux Fedora's shell marciano Linux - Newbie 1 10-19-2005 07:05 PM
Shell script to run pl/sql script. colly Linux - General 1 09-09-2004 07:49 AM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 10:49 PM
Shell script to configure IP Tables ??? jbrandis Linux - Security 2 12-11-2001 05:44 AM


All times are GMT -5. The time now is 07:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration