如何使用 ANT 任务启动 MySql

2021-11-11 00:00:00 mysql ant

我需要使用 ant 任务启动和停止 mysql 5.5.

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

早期的 ANT 脚本是为 hsqldb 数据库做的,它使用的类是 org.hsqldb.Server.有人能告诉我 mysql 5.5 使用哪个类.

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.

以下是在 hsqldb 用于 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>

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>

我需要 mysql 5.5 的等效项.我知道连接器是用来连接mysql 5.5数据库的,我用的是mysql-connector-java-5.1.15-bin.jar.

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.

谁能告诉我如何使用 ant 脚本启动和停止 mysql 数据库.

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

谢谢.

推荐答案

将 MySQL 配置为 机器启动时自动启动.MySQL 旨在在后台持续运行.

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

如果您真的想从 ANT 中停止和启动 MySQL,则可以调用服务器脚本(当然,假设 MySQL 与构建运行在同一台机器上).

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>

注意:

  • 此脚本包含在 windows 和 unix 上启动/停止的命令.
  • MySQL 文档描述了如何启动 Mysql从 windows 命令行

相关文章