How to upgrade MySQL database schema?

回眸只為那壹抹淺笑 提交于 2019-12-11 00:26:12

问题


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.


回答1:


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.

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

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.




回答2:


You can also use MySQL WorkBench: https://dev.mysql.com/downloads/workbench/ if you want an easy GUI, and cross OS compatible ;)



来源:https://stackoverflow.com/questions/47170885/how-to-upgrade-mysql-database-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!