MySQL Liquibase - 如何为现有数据库生成变更日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12449824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Liquibase - how to generate a changelog for existing database
提问by Dave
I'm trying to use liquibase for generating the changeLog, starting by snapshoting the current state of my database.
我正在尝试使用 liquibase 来生成 changeLog,首先是对我的数据库的当前状态进行快照。
Environment details:
环境细节:
- OS: Windows 7 32 x86,
- Java JDK 1.7,
- mysql jdbc driver from MySQL
- liquibase 2.0.5.
- 操作系统:Windows 7 32 x86,
- Java JDK 1.7,
- 来自 MySQL 的 mysql jdbc 驱动程序
- liquibase 2.0.5。
I run the following from command line:
我从命令行运行以下命令:
liquibase --driver=com.mysql.jdbc.Driver --changeLogFile=./structure.xml --url="jdbc:mysql://mysql.mysite.com" --username=<myuser> --password=<mypass> generateChangeLog
It runs fine, and generated the output file. But the output file just contains:
它运行良好,并生成了输出文件。但输出文件只包含:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"/>
And no tables are created on my database (I was expecting the two tables used for tracking).
并且我的数据库上没有创建表(我期待用于跟踪的两个表)。
What am I missing?
我错过了什么?
EDITS
编辑
Yes, I'm referring to liquibasechanlog and liquibasechangelock tables. I know they should automatically appears on database. My question is why they aren't there. And yes, the provided user have the rights granted for doing such task.
是的,我指的是 liquibasechanlog 和 liquibasechangelock 表。我知道它们应该自动出现在数据库中。我的问题是为什么他们不在那里。是的,提供的用户具有执行此类任务的权限。
And it is not an empty database. It has near 20 tables, 10 views, data...
它不是一个空的数据库。它有近 20 个表、10 个视图、数据...
采纳答案by Marian Zagoruiko
Just specify the database name with the --url
flag like ZNKsaid:
只需使用ZNK所说的--url
标志指定数据库名称:
--url="jdbc:mysql://mysql.mysite.com/database_name_here"
回答by Narasimha
I had faced similar issue when generating changelog xml for postgresql database. I'm posting here if it can help someone.
I had to specify --defaultSchemaName
in addition to the above params. So in mysql you will have similar option:
我在为 postgresql 数据库生成更改日志 xml 时遇到了类似的问题。如果它可以帮助某人,我会在这里发布。--defaultSchemaName
除了上述参数之外,我还必须指定。所以在 mysql 你会有类似的选项:
The final command will look like :
最终命令将如下所示:
liquibase --driver=org.postgresql.Driver --changeLogFile=db.changelog.xml --classpath=postgresql-9.4-1201-jdbc41.jar --url="jdbc:postgresql://localhost:5432/wms" --username=<USER_NAME> --password=<PASSWD> --defaultSchemaName=<SCHEMA_NAME> generateChangeLog
回答by khodayar J
After creating the initial changelog file , you should execute 'changelogsync' , it will create those tables in your database and updates them , also records the current state of your changelog as 'already ran' (so won't execute in next updates)
创建初始变更日志文件后,您应该执行“changelogsync”,它将在您的数据库中创建这些表并更新它们,还将变更日志的当前状态记录为“已运行”(因此不会在下次更新中执行)