How do I put MySQL code in the original control?

I know I can copy all my MySQL code manually into files and then put those files in the original control. But is there a way to do this automatically?

I would like to do this for stored procedures, but also table / event / trigger scripts.

+2


a source to share


3 answers


Based on Michal's answer, the solution I have been using so far is:



#!/bin/bash
BACKUP_PATH=/root/database_name
DATABASE=database_name
PASSWORD=Password
rm -f "$BACKUP_PATH/*.sql"
mysqldump -p$PASSWORD --routines --skip-dump-date --no-create-info --no-data --skip-opt $DATABASE > $BACKUP_PATH/$DATABASE.sql
mysqldump -p$PASSWORD --tab=$BACKUP_PATH --skip-dump-date --no-data --skip-opt $DATABASE
hg commit -Am "automatic commit" $BACKUP_PATH

      

+3


a source


You can create triggers when data changes, which would automatically save the change to a control source. However, there is no automatic way to track structure changes (tables, stored procedures, etc.) this way. Therefore, probably the best way is to dump the database and keep these dumps in source control. You can do this periodically to automate things.



+4


a source


I don't understand what you are trying to do.

Have a look at Liquibase , maybe it will do what you need ...

+1


a source







All Articles