为迁移数据生成DDL SQL语句脚本

The NuoDB Migrator tool also supports a schema command that can be used to generate DDL SQL statement scripts for dropping and creating one or more objects from a source database. 这还可以包括源模式中定义的所有对象。使用以下命令生成DDL SQL语句以删除并创建源数据库模式中定义的所有对象。 For MySQL, replace --source.schema=my_schema with --source.catalog=my_schema.

nuodb-migrator schema                            \
        --source.driver=source_driver_class_name \
        --source.url=jdbc:source_jdbc_url        \
        --source.schema=my_schema                \
        --source.username=userid                 \
        --source.password=passwd                 \
        --output.path=path_for_ddl_sql_file

Similar to how the NuoDB Migrator load command creates objects in a target NuoDB database, this generated DDL SQL will map source database data types to NuoDB supported data types. CREATE对象命令将从源数据库特定于SQL语法转换为Nuodb SQL支持的语法。

有命令行选项可以指定生成的DDL SQL语句将创建的对象类型。 For example, if the NuoDB Migrator tool was used to dump and load only table and sequence objects and data, this schema command would be used to generate DDL SQL statement scripts to create the remaining objects in the target NuoDB database. 以下架构命令将为主键,外键和其他索引生成DDL:

nuodb-migrator schema                            \
        --source.driver=source_driver_class_name \
        --source.url=jdbc:source_jdbc_url        \
        --source.schema=my_schema                \
        --source.username=userid                 \
        --source.password=passwd                 \
        --output.path=path_for_ddl_sql_file      \
        --meta.data.table=false                  \
        --meta.data.check=false                  \
        --meta.data.identity=false               \
        --meta.data.column.trigger=false         \
        --meta.data.primary.key=true             \
        --meta.data.foreign.key=true             \
        --meta.data.index=true

可以通过提供目标Nuodb JDBC连接参数来执行该DDL SQL语句脚本,如下所示:

nuodb-migrator schema                                        \
        --source.driver=source_driver_class_name             \
        --source.url=jdbc:source_jdbc_url                    \
        --source.schema=my_schema                            \
        --source.username=userid                             \
        --source.password=passwd                             \
        --output.path=path_for_ddl_sql_file                  \
        --target.url=jdbc:com.nuodb://host/database_name     \
        --target.username=userid                             \
        --target.password=passwd

This DDL SQL statement script can also be executed by using the NuoDB SQL command nuosql as follows:

$ nuosql [.var]__database_name__@[.var]__host__  --user userid --password passwd --schema schema \
    --file path_for_ddl_sql_file > output.log

标准输出和错误消息显示到屏幕,但可以重定向到输出日志文件。