如何升级MySQL数据库架构? [英] How to upgrade MySQL database schema?

查看:133
本文介绍了如何升级MySQL数据库架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过命令行自动从开发数据库模式升级生产数据库模式?开发版本对需要在生产模式中进行的模式进行了更改,但是我不能丢失生产中的数据。

How to upgrade a production DB schema from a dev DB schema automatically, via command line? The dev version has changes to the schema that need to be made in the production schema, but I cannot lose the data in production.

推荐答案

< h1> 架构迁移

大多数现代项目使用工具来跟踪对数据库的每个单独更改,并将某个版本号与该更改相关联。数据库还必须具有一些表以存储其当前版本。这样,该工具可以查询当前版本并确定要应用的更改(如果有的话)。

Schema Migrations

Most modern projects use a tool to track each individual change to the database, and associate some version number with the change. The database must also have some table to store its current version. That way the tool can query the current version and figure out which (if any) changes to apply.

有几种免费工具可以执行此操作,例如:

There are several free tools to do this, like:

  • Liquibase
  • Flyway
  • Rails Migrations
  • Doctrine Migrations
  • SQLAlchemy Migrate

所有这些都要求在开发过程中,您需要为每个更改编写细致的代码文件。如果您一直都不遵循创建模式更改代码的过程,那么对项目进行反向工程将很困难。

All of these require that you write meticulous code files for each change as you develop. It would be hard to reverse-engineer a project if you haven't been following the process of creating schema change code all along.

有类似 mysqldbcompare 可以帮助您生成最小的ALTER TABLE语句来升级您的生产数据库。

There are tools like mysqldbcompare that can help you generate the minimal ALTER TABLE statements to upgrade your production database.

还有一个名为的较新的免费工具。 Shift (我与创建它的工程师一起工作),有助于自动化升级数据库的过程。它甚至提供了一个不错的Web界面,用于输入模式更改,将其作为在线更改运行以及监视其进度。但是使用此工具需要大量经验,我不建议初学者使用。

There is also a newer free tool called Shift (I work with the engineer who created it), which helps to automate the process of upgrading your database. It even provides a nice web interface for entering your schema changes, running them as online changes, and monitoring their progress. But it requires quite a lot of experience to use this tool, I wouldn't recommend it for a beginner.

这篇关于如何升级MySQL数据库架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆