Search code examples
mysqlversion-controlsql-scripts

How to put MySQL code into source control?


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

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


Solution

  • Based on Michal answer, the solution I am 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