Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:34:54+00:00 2026-06-15T01:34:54+00:00

I have two servers which contains a same database, same tables structure with different

  • 0

I have two servers which contains a same database, same tables structure
with different values. I need to compare the count of a column(ID) in both of
them for a table1 and if server1’s db’s table1’s max(ID)>max(ID) of server2’s db’s
table1 then Insert all the new records from server1 to server2

I need to keep this logic inside a shell scripts so that when I call the .sh file
it will do the job for me. I want to do it from my local machine which has access to
these servers.

how can the compare will happen inside a shell script. I m using Mysql DB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:34:55+00:00Added an answer on June 15, 2026 at 1:34 am

    From what I get from your statement is that you want to keep checking if any of the tables has more records than the other one. And duplicate the table with more entries. What I would suggest is, since you want to use a script file to automate the task, I’ll give you two methods:

    (i) Instead of comparing the column ids, you can create a mysql-dump-file for each table and check which one has more number of characters in it by comparing size. The one with the more is obviously, more populated. So, overwrite the small table with the dump of the larger one.

     mysqldump -u <username> -p<password> -h <address> <schema> <table>  > <output-file>.sql
    

    (ii) First store the output of COUNT(*) for both the tables in two variables and compare them.

      $tableCount1=$(`echo mysql -u <username> -p<password> -h <address> < <input-file>.sql` | cut -d' ' -f2)
    

    Where your input-file will have the content:

      USE <schema>
      SELECT COUNT(*) FROM <table>;
    

    Compare the ids, and then replace the smaller table with the dump of the larger table!

    If you don’t want to replace the whole table, then use:

     mysqldump -u <username> -p<password> -h <address> <schema> <table> --skip-triggers --compact --no-create-info --where=<column_id> > <id> > <output-file>.sql
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: servers and stats servers has a column called id that
Currently I have an object which I receive from a server, this contains two
You have two servers when you perform a SQL Server database mirroring You have
I have two grails servers: Server - has read/write access to the database Web
I have two tables with the exact same schema in SQL Server 2008 Standard
Suppose I have a database which contains blog posts which have tags and I
I have two copies of the same directory structure (basically, trunk and a feature
I have two models: first one is PersonAddress , which contains info about person
I have two tables with hierarchyid fields, one of which is a staging table
I wonder if anyone can advise? I have a JSP which contains two forms,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.