2008-10-02 48 views
3

我一直在考慮這個問題並且還沒有想出任何穩定/優雅的想法。當代碼庫沒有ORM時對MySQL數據庫進行版本控制

我知道在MyISAM表中,你可以得到表def的更新時間,但這與InnoDB不一樣,我發現它甚至不可靠查看.frm文件,以瞭解何時定義可能有被修改....如果數據集已被更改,永不知情。

我有一個想法,每隔30分鐘mysqldumping模式的內容,用AWK腳本分開,然後區分到最後一個版本......但這似乎有點過分,可能是一個問題,如果涉及的數據集很大。

+0

什麼是版本控制?數據庫的基本模式?或者你想跟蹤數據的所有更改? – Ken 2008-10-02 19:21:48

回答

0

是的,這很難。這就是我使用innodb的原因。做轉儲/導入更容易,我們甚至把模式放在VC下。

+0

InnoDB一直非常惡毒地處理轉儲/導入,特別是重建索引。另一個時間和地點我在早上開始進口,晚上晚些時候完成(索引關閉直到進口完成)。 – David 2008-12-18 23:28:42

2

如果運行mysqldump -d只轉儲模式:

[[email protected] ~]$ mysqldump -d -u root mysql user 
-- MySQL dump 10.11 
-- 
-- Host: localhost Database: mysql 
-- ------------------------------------------------------ 
-- Server version  5.0.45 

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; 
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; 
/*!40101 SET @[email protected]@COLLATION_CONNECTION */; 
/*!40101 SET NAMES utf8 */; 
/*!40103 SET @[email protected]@TIME_ZONE */; 
/*!40103 SET TIME_ZONE='+00:00' */; 
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */; 

-- 
-- Table structure for table `user` 
-- 

DROP TABLE IF EXISTS `user`; 
CREATE TABLE `user` (
    `Host` char(60) collate utf8_bin NOT NULL default '', 
    `User` char(16) collate utf8_bin NOT NULL default '', 
    `Password` char(41) character set latin1 collate latin1_bin NOT NULL default '', 
    `Select_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Insert_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Update_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Delete_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Create_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Drop_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Reload_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Shutdown_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Process_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `File_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Grant_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `References_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Index_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Alter_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Show_db_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Super_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Create_tmp_table_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Lock_tables_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Execute_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Repl_slave_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Repl_client_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Create_view_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Show_view_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Create_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Alter_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `Create_user_priv` enum('N','Y') character set utf8 NOT NULL default 'N', 
    `ssl_type` enum('','ANY','X509','SPECIFIED') character set utf8 NOT NULL default '', 
    `ssl_cipher` blob NOT NULL, 
    `x509_issuer` blob NOT NULL, 
    `x509_subject` blob NOT NULL, 
    `max_questions` int(11) unsigned NOT NULL default '0', 
    `max_updates` int(11) unsigned NOT NULL default '0', 
    `max_connections` int(11) unsigned NOT NULL default '0', 
    `max_user_connections` int(11) unsigned NOT NULL default '0', 
    PRIMARY KEY (`Host`,`User`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges'; 
/*!40103 SET [email protected]_TIME_ZONE */; 

/*!40101 SET [email protected]_SQL_MODE */; 
/*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */; 
/*!40014 SET [email protected]_UNIQUE_CHECKS */; 
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */; 
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */; 
/*!40101 SET [email protected]_COLLATION_CONNECTION */; 
/*!40111 SET [email protected]_SQL_NOTES */; 

-- Dump completed on 2008-10-02 20:06:38 

那麼你可以做你的分析。

你的問題還有另一種解決方案,但需要紀律。您可以添加COMMENT字段到列和表格:

CREATE TABLE example (
    name varchar(32) COMMENT='Name of a person' 
) COMMENT='example table'; 

我喜歡在其中放入一個版本號。你可以配合該到你的RCS:

CREATE TABLE example (
    name varchar(32) COMMENT='Name of a person' 
) COMMENT='VERSION=1.2.3 example table';