Database Version Control for MySQL

后端 未结 4 1422
别那么骄傲
别那么骄傲 2020-12-19 15:38

What method do you use to version-control your database? I\'ve committed all our database tables as separate .sql scripts to our respository (mercurial). In that way, if any

4条回答
  •  独厮守ぢ
    2020-12-19 16:11

    I'm not sure how well this answers your question, but I tend to just use mysqldump (part of the standard installation). This gives me the sql to create the tables and populate them, effectively serializing the database. Example:

    > mysqldump -u username -p yourdatabase > database_dump.sql
    

    To load a database from a dump sql file:

    mysql -u username -p -e "source /path/to/database_dump.sql"

    To further answer your question, I would version control each table separately only if there are multiple people working on the database in such a way that conflicts are likely to occur with just a single dump being version controlled. I've never hit a project where this is the case (the database tends to be one of the least volatile portions of the system after the initial phases of the project), so I just version control the database dump as a whole rather than each table individually.

提交回复
热议问题