MySql中的DELIMITER错误

时间:2011-12-14 12:18:16

标签: mysql ant delimiter

我正在使用以下sql:

DELIMITER $$

DROP PROCEDURE IF EXISTS `get_auto_increment_settings`$$

CREATE PROCEDURE `get_auto_increment_settings`()
BEGIN   
    select @@global.auto_increment_offset as 'offset', @@global.auto_increment_increment as 'increment' ;

END $$
DELIMITER ;

我将它存储在db_auto_increment_settings_procedure.sql中,当我尝试从ant执行此操作时,我遇到以下错误:

[sql] Executing resource: /mysql/install/db_auto_increment_settings_procedure.sql
[sql] Failed to execute:  DELIMITER
[sql] com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1
[sql] Failed to execute:  DELIMITER ;
[sql] com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1

2 个答案:

答案 0 :(得分:7)

分隔符仅由mysql客户端使用(不在API,驱动程序等) 所以,它不会起作用。

请参阅错误消息: -

[sql] Executing resource: /mysql/install/db_auto_increment_settings_procedure.sql  
[sql] Failed to execute:  DELIMITER

非常确定这适用于linux系统

mysql -u root -pxxx -h yyy < YOUR_SQL.sql

如果适用,您只需使用mysql客户端手动创建存储过程,
并且是一个无汗的解决方案。

如果您需要动态创建,请执行此操作 这个文档可能会提供一些洞察信息 http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-basic.html

答案 1 :(得分:1)

您的程序有一个命令,因此不需要分隔符 -

DROP PROCEDURE IF EXISTS `get_auto_increment_settings`;

CREATE PROCEDURE `get_auto_increment_settings`()
SELECT @@global.auto_increment_offset AS 'offset', @@global.auto_increment_increment AS 'increment';