簡體   English   中英

DDLUtils不使用Ant腳本導出Mysql數據

[英]DDLUtils not exporting Mysql data using ant script

我想在ant中使用ddlutils工具導出mysql數據庫

 <target name="export-source-db" description="Dumps db structure and data">
      <taskdef name="databaseToDdl"
              classname="org.apache.ddlutils.task.DatabaseToDdlTask">
    <classpath refid="libraries"/>
    <classpath refid="mysqlclasspath"/>
      </taskdef>

      <databaseToDdl modelName="bwfla">
         <database url="jdbc:mysql://localhost:3306/"
                 driverClassName="com.mysql.jdbc.Driver"
                 username="root"
                 password="sriram"/>
         <writeSchemaToFile outputFile="db-schema.xml"/>
         <writeDataToFile outputFile="data.xml"/>
      </databaseToDdl>

   </target>

但是如果我檢查db-schema.xml

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database">
  <database name="bwfla"/>

和data.xml是

<?xml version='1.0' encoding='UTF-8'?>
<data>
</data>

它沒有導出數據。 誰能幫我。

我認為您的問題是數據庫URL:

jdbc:mysql://localhost:3306/

您尚未指定要連接的數據庫。 應該是這樣的:

jdbc:mysql://localhost:3306/my_db_name_goes_here

我也建議不要以“ root”身份連接。 創建一個可以訪問數據庫的mysql用戶。

撇開 結帳liquibase 我認為這是用於管理數據庫架構的更強大的工具。

工作實例

我使用apache ivy來管理我的第三方依賴項。 只需忽略“引導程序”和“解決”目標即可。

<project name="ddutils" default="create" xmlns:ivy="antlib:org.apache.ivy.ant">

   <property name="db.driver"   value="com.mysql.jdbc.Driver"/>
   <property name="db.url"      value="jdbc:mysql://localhost:3306/example1"/>
   <property name="db.username" value="example1"/>
   <property name="db.password" value="pleasechangeme"/>

   <target name="bootstrap" description="Install ivy">
      <mkdir dir="${user.home}/.ant/lib"/>
      <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
   </target>

   <target name="resolve" description="Resolve 3rd party dependencies">
      <ivy:cachepath pathid="build.path">
         <!-- Database -->
         <dependency org="mysql" name="mysql-connector-java" rev="5.1.25" conf="default"/>

         <!-- ddlutils plus dependency fixes -->
         <dependency org="org.apache.ddlutils" name="ddlutils" rev="1.0" conf="default"/>
         <dependency org="xml-apis" name="xml-apis" rev="1.0.b2" conf="default" force="true"/>
         <dependency org="xerces" name="xercesImpl" rev="2.11.0" conf="default"/>
         <exclude org="xerces" module="xerces"/>

         <!-- logging libraries -->
         <dependency org="org.slf4j" name="slf4j-simple" rev="1.7.5" conf="default"/>
         <dependency org="org.slf4j" name="log4j-over-slf4j" rev="1.7.5" conf="default"/>
      </ivy:cachepath>
   </target>

   <target name="create" depends="resolve" description="Create tables and data">
      <sql driver="${db.driver}" url="${db.url}" userid="${db.username}" password="${db.password}" classpathref="build.path">
         CREATE TABLE example1 (id INT, one VARCHAR(30), two VARCHAR(30), PRIMARY KEY(id));
         INSERT INTO example1 VALUES (0, 'hello', 'world');
         INSERT INTO example1 VALUES (1, 'hello', 'world');
         INSERT INTO example1 VALUES (2, 'hello', 'world');
         INSERT INTO example1 VALUES (3, 'hello', 'world');
         INSERT INTO example1 VALUES (4, 'hello', 'world');
         INSERT INTO example1 VALUES (5, 'hello', 'world');
         INSERT INTO example1 VALUES (6, 'hello', 'world');
         INSERT INTO example1 VALUES (7, 'hello', 'world');
         INSERT INTO example1 VALUES (8, 'hello', 'world');
         INSERT INTO example1 VALUES (9, 'hello', 'world');

         CREATE TABLE example2 (id INT, one VARCHAR(30), two VARCHAR(30), PRIMARY KEY(id));
         INSERT INTO example2 VALUES (0, 'hello', 'world');
         INSERT INTO example2 VALUES (1, 'hello', 'world');
         INSERT INTO example2 VALUES (2, 'hello', 'world');
         INSERT INTO example2 VALUES (3, 'hello', 'world');
         INSERT INTO example2 VALUES (4, 'hello', 'world');
         INSERT INTO example2 VALUES (5, 'hello', 'world');
         INSERT INTO example2 VALUES (6, 'hello', 'world');
         INSERT INTO example2 VALUES (7, 'hello', 'world');
         INSERT INTO example2 VALUES (8, 'hello', 'world');
         INSERT INTO example2 VALUES (9, 'hello', 'world');
      </sql>
   </target>

   <target name="extract" depends="resolve" description="Use DDLUtils to extract schema and data">
      <taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask" name="databaseToDdl" classpathref="build.path" />

      <databaseToDdl usedelimitedsqlidentifiers="true" modelname="example">
         <database driverclassname="${db.driver}" url="${db.url}" username="${db.username}" password="${db.password}"/> 
         <writeschematofile outputfile="build/schema.xml"/> 
         <writedatatofile   outputfile="build/data.xml" encoding="ISO-8859-1"/> 
      </databaseToDdl> 
   </target>

   <target name="clean" description="Cleanup project files">
      <delete dir="build"/>
   </target>

   <target name="clean-all" depends="clean" description="Cleanup project files">
     <ivy:cleancache/>
   </target>

</project>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM