天天看点

数据库结构版本控制

中国广东省深圳市龙华新区民治街道溪山美地

518131

+86 13113668890

+86 755 29812080

版权 © 2014 http://netkiller.github.io

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

数据库结构版本控制

文档出处:

<a href="http://netkiller.github.io/" target="_top">http://netkiller.github.io</a>

<a href="http://netkiller.sourceforge.net/" target="_top">http://netkiller.sourceforge.net</a>

2014-12-17

摘要

我的系列文档

<a href="http://netkiller.github.io/architect/index.html" target="_top">netkiller architect 手札</a>

<a href="http://netkiller.github.io/developer/index.html" target="_top">netkiller developer 手札</a>

<a href="http://netkiller.github.io/php/index.html" target="_top">netkiller php 手札</a>

<a href="http://netkiller.github.io/python/index.html" target="_top">netkiller python 手札</a>

<a href="http://netkiller.github.io/testing/index.html" target="_top">netkiller testing 手札</a>

<a href="http://netkiller.github.io/cryptography/index.html" target="_top">netkiller cryptography 手札</a>

<a href="http://netkiller.github.io/linux/index.html" target="_top">netkiller linux 手札</a>

<a href="http://netkiller.github.io/debian/index.html" target="_top">netkiller debian 手札</a>

<a href="http://netkiller.github.io/centos/index.html" target="_top">netkiller centos 手札</a>

<a href="http://netkiller.github.io/freebsd/index.html" target="_top">netkiller freebsd 手札</a>

<a href="http://netkiller.github.io/shell/index.html" target="_top">netkiller shell 手札</a>

<a href="http://netkiller.github.io/security/index.html" target="_top">netkiller security 手札</a>

<a href="http://netkiller.github.io/www/index.html" target="_top">netkiller web 手札</a>

<a href="http://netkiller.github.io/monitoring/index.html" target="_top">netkiller monitoring 手札</a>

<a href="http://netkiller.github.io/storage/index.html" target="_top">netkiller storage 手札</a>

<a href="http://netkiller.github.io/mail/index.html" target="_top">netkiller mail 手札</a>

<a href="http://netkiller.github.io/docbook/index.html" target="_top">netkiller docbook 手札</a>

<a href="http://netkiller.github.io/version/index.html" target="_top">netkiller version 手札</a>

<a href="http://netkiller.github.io/database/index.html" target="_top">netkiller database 手札</a>

<a href="http://netkiller.github.io/postgresql/index.html" target="_top">netkiller postgresql 手札</a>

<a href="http://netkiller.github.io/mysql/index.html" target="_top">netkiller mysql 手札</a>

<a href="http://netkiller.github.io/nosql/index.html" target="_top">netkiller nosql 手札</a>

<a href="http://netkiller.github.io/ldap/index.html" target="_top">netkiller ldap 手札</a>

<a href="http://netkiller.github.io/network/index.html" target="_top">netkiller network 手札</a>

<a href="http://netkiller.github.io/cisco/index.html" target="_top">netkiller cisco ios 手札</a>

<a href="http://netkiller.github.io/h3c/index.html" target="_top">netkiller h3c 手札</a>

<a href="http://netkiller.github.io/multimedia/index.html" target="_top">netkiller multimedia 手札</a>

<a href="http://netkiller.github.io/perl/index.html" target="_top">netkiller perl 手札</a>

<a href="http://netkiller.github.io/radio/index.html" target="_top">netkiller amateur radio 手札</a>

<a href="http://netkiller.github.io/devops/index.html" target="_top">netkiller devops 手札</a>

目录

<a href="http://netkiller.github.io/journal/mysql.struct.html#what">1. 什么是数据库结构版本控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#why">2. 为什么要做数据库结构本版控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#when">3. 何时做数据库结构本版控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#where">4. 在哪里做数据库结构本版控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#who">5. 谁来负责数据库结构本版控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#how">6. 怎样做数据库结构本版控制</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#idp63273824">6.1. 安装脚本</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#idp63278640">6.2. 启动脚本,停止脚本</a>

<a href="http://netkiller.github.io/journal/mysql.struct.html#idp63282416">6.3. 查看历史版本</a>

数据库结构是指数据库表结构,数据库定义语言导出的ddl语句。主要由create table, drop table等等构成。

再来说说什么事版本控制,如果你从事开发工作应该会很容易理解,版本控制就是记录每一次变化,可以随时查看历史记录,并可回撤到指定版本。

软件开发过程中需要常常对数据库结构作调整,这是无法避免的,甚至很多想起启动后,需求还不明确,开发人员只能按照所理解需求创建表。需求往往会发生变化,一旦变化,代码需要修改,表结构也避免不了。 我们常常刚改好数据库结构,需求部门有发来通知,不用修改了,维持原有设计。甚至是过了几周再次回撤。

所以我们要将数据库结构的变化进行版本控制,通常的做法是dba人工管理,但我觉完全可以自动化的工作,没有必要浪费人力资源,且自动化不会犯错更稳定,仅仅需要人工定期查看工作状态即可。

任何时候都可以部署下面的脚本,对现有系统无任何影响。

dba与配置管理员都可以做,通常dba不接触版本库这块,建议创建一个backup用户给配置管理员。

创建备份用户

配置脚本

初始化仓库

开始脚本

查看状态

停止脚本

通过 git log 命令查看历史版本