To create MySQL database using Ant, do the followings:
- Save the XML code below in a file, e.g.
create_database.xml
. - Change
mydatabasename
from the XML code below to the database name that you want. - Run the following from Command prompt:
ant -f create_database.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="create_db" name="Create 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 create a database. --> <target name="create_db"> <exec executable="${mysqladmin}"> <arg value="--user=${mysql.username}"/> <arg value="--password=${mysql.pwd}"/> <arg value="CREATE"/> <arg value="${mysql.dbname}"/> </exec> </target> </project>