Search code examples
javaantmysql

How do I dump a MySQL database using ant?


I couldn't find any information about how to dump a MySQL database with an ant task.

Do I have to create my own task to do this?

ANT script ===generate==> myDataBase.sql

Solution

  • Create a target that runs the "mysqldump" command like this:

    <target name="dump-database">  
        <exec executable="mysqldump" output="database-dump.sql">  
            <arg value="--user=username" />  
            <arg value="--password=password" />  
            <arg value="--host=localhost" />  
            <arg value="--port=3306" />  
            <arg value="mydatabase" />  
        </exec>  
    </target>  
    

    Now you can make the dump by executing ant dump-database