Delete MySQL database using Ant

By xngo on June 18, 2019

To delete MySQL database using Ant, do the followings:

  1. Save the XML code below in a file, e.g. delete_database.xml.
  2. Change mydatabasename from the XML code below to the database name that you want to delete.
  3. Run the following from Command prompt:
ant -f delete_database.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="delete_db" name="Delete a database in mysql using Ant">
 
  <!-- The following properties need to be changed according to your environment.-->
  <property name="mysqladmin" value="C:\wamp\bin\mysql\mysql5.1.36\bin\mysqladmin.exe"/>
  <property name="mysql.username" value="root"/>
  <property name="mysql.pwd" value="mypassword"/>
  <property name="mysql.dbname" value="mydatabasename"/>
 
  <!-- mysqladmin is used to delete a database. -->
  <target name="delete_db">
    <exec executable="${mysqladmin}">
      <arg value="--user=${mysql.username}"/>
      <arg value="--password=${mysql.pwd}"/>
      <arg value="--force"/>
      <arg value="DROP"/>
      <arg value="${mysql.dbname}"/>
    </exec>
  </target>
 
</project>

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.