如何升级MySQL数据库架构?

编程入门 行业动态 更新时间:2024-10-28 15:27:19
本文介绍了如何升级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.

推荐答案

架构迁移

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

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
  • 飞行路线
  • 铁路迁移
  • Doctrine迁移
  • SQLAlchemy迁移
  • 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数据库架构?

本文发布于:2023-07-14 13:39:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   数据库   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!