tortoisegit - 有没有办法在提交git之前自动导出mysql数据库
阿神
阿神 2017-04-17 11:18:34
0
3
639

也有看到一些,数据库版本控制解决方案,
比如Laravel自带的那个,还有dbv.php……
但是我觉得还不如直接在提交前 导出一下数据表结构的SQL文件。

有没有办法在提交git之前自动导出mysql数据库呢。
想把数据表结构也加入版本控制里。
我用的是TortoiseGit。

阿神
阿神

闭关修行中......

reply all(3)
左手右手慢动作

pre-commit git hook

There should be a directory .git/hooks/ in your repo root directory (hidden directories need to be displayed first), and create a new file pre-commit in it (the current user needs to have execution permissions). The content is roughly as follows:

#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

/usr/local/opt/mysql/bin/mysqldump -uroot -p111111 -S /tmp/mysql-3306.socket dbname --no-data > path/to/dbfile/dbname.sql

git add path/to/dbfile/dbname.sql

The above mysql user, password, and dbname must become your own.

Peter_Zhu

Support @samoay's answer.
But there is a tip, the pre-commit hook is a client-side hook.
You will need to copy this hook file to your co-developers if they need it.

Peter_Zhu

git hooksis your good partner

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template