skip
skip

Reputation: 12673

How to start MySql using ANT task

I need to start and stop mysql 5.5 using ant task.

The earlier ANT script was doing it for hsqldb database for which the class it was using was org.hsqldb.Server. Could someone tell me which class to use for mysql 5.5.

Following was being use in case of hsqldb for mydb: <java fork="true" spawn="true" classname="org.hsqldb.Server" classpathref="build.runtime.classpath"> <arg line="-database.0 file:data/mydb -dbname.0 mydb"/> </java>

I need to have the eqivalant for mysql 5.5. I know a connector is used to connect to mysql 5.5 database, I use mysql-connector-java-5.1.15-bin.jar.

Could someone just tell me how to start and stop mysql database using an ant script.

Thanks.

Upvotes: 0

Views: 1740

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 78001

It would be more normal to configure MySQL to automatically start when the machine boots. MySQL is designed to run continually in the background.

If you really want to stop and start MySQL from within ANT it's possible to invoke the server scripts (Assuming of course MySQL is running on the same machine as the build).

<target name="start-db">
  <exec executable="C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" osfamily="windows">
  </exec>

  <exec executable="mysql.server" osfamily="unix">
    <arg value="start"/>
  </exec>
</target>

<target name="stop-db">
  <exec executable="C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" osfamily="windows">
    <arg value="-u"/>
    <arg value="root"/>
    <arg value="shutdown"/>
  </exec>

  <exec executable="mysql.server" osfamily="unix">
    <arg value="stop"/>
  </exec>
</target>

Note:

Upvotes: 1

Related Questions