MySQL DELIMITER 语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1102109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:38:34  来源:igfitidea点击:

MySQL DELIMITER syntax errors

sqlmysqltriggersdelimiter

提问by Sophia

This MySQL script installs multiple triggers.

这个 MySQL 脚本安装了多个触发器。

It works on one machine running MySQL 5.0.51b-community. On another machine running MySQL 14.12 Distrib 5.0.45, for redhat-linux-gnu (i386) it fails, with this error message, which seems to be related to the DELIMITER // ... // DELIMITER; syntax :

它适用于一台运行 MySQL 5.0.51b-community 的机器。在另一台运行 MySQL 14.12 Distrib 5.0.45 的机器上,对于 redhat-linux-gnu (i386),它失败了,并显示此错误消息,这似乎与DELIMITER // ... // DELIMITER; 句法 :

ERROR 1064 (42000) at line 272: 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; DROP TRIGGER IF EXISTS trigger_name; DELIMITER' at line 1

第 272 行的 ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在“DELIMITER”附近使用的正确语法;DROP TRIGGER IF EXISTS trigger_name; 第 1 行的 DELIMITER'

The script syntax (summarised) is:

脚本语法(总结)是:

DROP TRIGGER IF EXISTS trigger_name;
DELIMITER //
CREATE TRIGGER trigger_name BEFORE UPDATE ON table
FOR EACH ROW BEGIN
  -- Trigger logic goes here
END //
DELIMITER;

-- More trigger drop/create statements follow

What is wrong with the script, and how can I correct it?

脚本有什么问题,我该如何纠正?

回答by chaos

Try

尝试

DELIMITER ;

not

不是

DELIMITER;

You're actually specifying ;as an argument to the DELIMITERcommand, so not having the space there may be confusing it.

您实际上是指定;DELIMITER命令的参数,因此没有空格可能会混淆它。

回答by too much php

You need a space between 'DELIMITER' and ';'

'DELIMITER' 和 ';' 之间需要一个空格

DELIMITER ;
# not:
DELIMITER;

回答by Tebo

Just as an add-on, for someone else:

就像一个附加组件,对于其他人:

The delimiter is required to enable the entire definition to be passed to the server as a single statement.

需要分隔符才能将整个定义作为单个语句传递到服务器。

回答by lxblanco

In the version of MySql I use the same error occurs when using the delimiter command, but this version handles the delimiter ";" for statements and delimiter "|" for stored procedures and functions, which i think solves the problem; try this:

在 MySql 的版本中,我使用 delimiter 命令时出现同样的错误,但是这个版本处理了分隔符“;” 用于语句和分隔符“|” 对于存储过程和函数,我认为可以解决问题;尝试这个:

DROP TRIGGER IF EXISTS trigger_name;

DROP TRIGGER IF EXISTS trigger_name;

CREATE TRIGGER trigger_name BEFORE UPDATE ON table FOR EACH ROW BEGIN -- Trigger logic goes here END |

-- other statements or functions here

CREATE TRIGGER trigger_name BEFORE UPDATE ON table FOR EACH ROW BEGIN -- Trigger logic goes here END |

-- other statements or functions here

回答by user438441

Try the below.

试试下面的。

I am sure it should solve the purpose.

我相信它应该可以解决目的。

DELIMITER +
CREATE TRIGGER STUDENT_INSERT_TRIGGER BEFORE INSERT ON FSL_CONNECTIONS 
FOR EACH ROW BEGIN 
INSERT INTO STUDENT_AUDIT 
SET STUDENT_ID = NEW.STUDENT_ID, 
MAC_ADDRESS = NEW.MAC_ADDRESS,
IPADDRESS = NEW.IPADDRESS, 
EMAIL_ID = NEW.EMAIL_ID , 
START_TIME=NEW.START_TIME, 
END_TIME=NEW.END_TIME, 
STATUS=NEW.STATUS; 
END; +

From the above when we use a DELIMITER. It should be in the form of

从上面当我们使用 DELIMITER 时。它应该是这样的形式

DELIMITER +
--
BLOCK OF SQL WHATEVER YOU WANT TO MENTION
--
+

回答by user438441

Hmm I'm having similar problems. I do a mysqldump from Debian Lenny running 5.0.51 and try importing to OpenSolaris running 5.0 and get the same error. And I have DELIMITER ;

嗯,我也有类似的问题。我从运行 5.0.51 的 Debian Lenny 执行 mysqldump 并尝试导入到运行 5.0 的 OpenSolaris 并得到相同的错误。我有 DELIMITER ;

Version conflict?

版本冲突?