DELIMITER error in MySql

两盒软妹~` 提交于 2019-12-14 03:46:44

问题


I am using the following 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 ;

I stored this in db_auto_increment_settings_procedure.sql and when I am trying to execute this from ant, I am facing the following error:

[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

回答1:


The delimiter is used only by mysql client (not on API, driver ... etc).
So, it won't work.

See your error message :-

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

Pretty sure this will work in linux system

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

If applicable, you just manually create the stored procedure using mysql client,
and is a no-sweat solution.

If you need to create this dynamically,
this doc might provide some insight information
http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-basic.html




回答2:


Your procedure has one command, so delimiters are not needed -

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';


来源:https://stackoverflow.com/questions/8504325/delimiter-error-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!