Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-15-2017, 01:45 PM   #1
LQ Newbie
Registered: Feb 2016
Posts: 3

Rep: Reputation: Disabled
Compare tables record count from 2 different databases via shellscript


I want to compare the records count of around 200 tables from db1 with record count of same 200 tables from db2 thro she'll script, please let me know how we can do it in a simplified way using shellscript as we are planning to schedule this , any code snippet on this is really helpful. Since there ar 200 tables , we need to reduce the time as much as possible as well. Please provide your input with code snippet/ examples which will surely help us in this case.

Old 03-15-2017, 01:51 PM   #2
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,423
Blog Entries: 3

Rep: Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788Reputation: 3788
Yes, some of your code would help. Please show what you have started with and explain your approach so that we may provide advice. Also show some sample records from each table or explain how they are stored. Are they flat, tab separated values? Or are they in some kind of SQL database? We'll help you but not do your work for you, besides some of our hourly rates would scare you.
Old 03-16-2017, 07:32 AM   #3
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,890
Blog Entries: 13

Rep: Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934Reputation: 4934
Hi and welcome to LQ.

Please realize that forum members are here as volunteers and the way LQ works is that these volunteers are here to help you as you attempt to solve your own problem.

Therefore it is prudent that you show what you have tried and where you are stuck. People will certainly be willing to offer suggestions and improvements to you work, but people are not here to write your scripts for you.

Please post your code that you have.
Old 03-16-2017, 12:45 PM   #4
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
This looks like a very standard requirement for instance to test the integrity of a data base copy that first you should look for an existing solution in the help fora of your data base.

Still, if you want to do it in a shell script,
Is the list of "around 200 tables" fixed (so you can put it into a list or is is to be taken from the data dictionary by something like select tablename from iitables.. . Append the result to a 3 column array with the table name in the first column.

Next open (prepare .. whatever) the 2 data bases.
Cycle the array by index.
col2[index]=select count * from col1[index] from the first data base
col3[index]=select count * from col1[index] from the second data base
If the result differs, print the error message

Clearly this is just an idea without knowing about your database, resources etc.

Do try and let us know.


Last edited by AnanthaP; 03-16-2017 at 12:48 PM.


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
Compare and Update 2 columns from 2 tables in mysql sam@ Linux - Newbie 5 06-11-2015 02:58 AM
MySQL - Query and compare 2 tables rookiepaul Programming 4 05-12-2008 09:05 AM
Mysql Compare two tables from different databases baddah Programming 4 04-20-2006 12:36 AM
mysql count tables in a database Longinus Programming 2 04-11-2004 01:22 AM
Need to compare 2 databases. Help please! morbid_ru Programming 1 12-08-2003 04:16 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:18 PM.

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