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 4118516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:58:14+00:00 2026-05-20T22:58:14+00:00

If this is recommended ? Can I ask some git command examples about how

  • 0

If this is recommended ?

Can I ask some git command examples about how to track versions of mysql schema?

Should we use another repository other then the one we normally use on our application root ?

Should I use something called hook ?

Update:

1) We navigate onto our project root where .git database resides.

2) We create a sub folder called hooks.

3) We put something like this inside a file called db-commit:

   #!/bin/sh
   mysqldump -u DBUSER -pDBPASSWORD  DATABASE --no-data=true> SQLVersionControl/vc.sql
   git add SQLVersionControl/vc.sql
   exit 0

Now we can:

4) git commit -m

This commit will include a mysql schema dump that has been run just before the commit.

The source of the above is here:
http://edmondscommerce.github.io/git/using-git-to-track-db-schema-changes-with-git-hook.html

If this is an acceptable way of doing it, can I please ask someone with patience to comment line by line and with as much detail as possible, what is happening here:

#!/bin/sh
mysqldump -u DBUSER -pDBPASSWORD  DATABASE --no-data=true> SQLVersionControl/vc.sql
git add SQLVersionControl/vc.sql
exit 0

Thanks a lot.

  • 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-05-20T22:58:15+00:00Added an answer on May 20, 2026 at 10:58 pm

    Assuming you have a git repo already, do the following in a shell script or whatever:

    #!/bin/bash -e
    # -e means exit if any command fails
    DBHOST=dbhost.yourdomain.com
    DBUSER=dbuser
    DBPASS=dbpass # do this in a more secure fashion
    DBNAME=dbname
    GITREPO=/path/to/git/repo
    cd $GITREPO
    mysqldump -h $DBHOST -u $DBUSER -p$DBPASS -d $DBNAME > $GITREPO/schema.sql # the -d flag means "no data"
    git add schema.sql
    git commit -m "$DBNAME schema version $(`date`)"
    git push # assuming you have a remote to push to
    

    Then start this script on a daily basis from a cron job or what have you.

    EDIT: By placing a script in $gitdir/hooks/pre-commit (the name is important), the script will be executed before every commit. This way the state of the DB schema is captured for each commit, which makes sense. If you automatically run this sql script every time you commit, you will blow away your database, which does not make sense.

    #!/bin/sh
    

    This line specifies that it’s a shell script.

    mysqldump -u DBUSER -pDBPASSWORD  DATABASE --no-data=true> SQLVersionControl/vc.sql
    

    This is the same as in my answer above; taking the DDL only from the database and storing it in a file.

    git add SQLVersionControl/vc.sql
    

    This adds the SQL file to every commit made to your repository.

    exit 0
    

    This exits the script with success. This is possibly dangerous. If mysqldump or git add fails, you may blow away something you wanted to keep.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this still the recommended library in use? ThickBox 3.1
I have a prefix trie. What is the recommended schema for representing this structure
Which is the preferred/recommended way of handling events in .NET: this.Load += new EventHandler(Form1_Load);
Very similar to this question , except for Java. What is the recommended way
I would like to ask for a reccomended solution for this: We have a
What logging library or approach would you recommend for this case: We want to
Before anyone recommends that I do a google search on this, I have. I
W3C recommends putting a space before the closing tag in XHTML , because this
Version Control with Subversion recommends the following layout for (single-project) repositories (complemented by this
What Inversion of Control Container framework would you recommend to a beginner in this

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.