MySQL 中的错误 1064 (42000)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6998705/
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 20:48:39  来源:igfitidea点击:

ERROR 1064 (42000) in MySQL

mysqlazuremysql-error-1064

提问by siva636

I am trying to populate a new MySQL empty database with a db dump created from MS SQL Azure database, and I get the following error

我正在尝试使用从 MS SQL Azure 数据库创建的 db 转储填充新的 MySQL 空数据库,但出现以下错误

ERROR 1064 (42000) at line 1: 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 'I ' at line 1

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

I used mysqldump to perform this operation and used command similar to the following in the command prompt:

我使用 mysqldump 来执行此操作并在命令提示符中使用类似于以下的命令:

mysql --user=rootusername --pasword=password databasename < dumpfilename.sql

Mysqldump took about 30 minutes to display this error message.

Mysqldump 大约需要 30 分钟才能显示此错误消息。

回答by msanford

(For those coming to this question from a search engine), check that your stored procedures declare a custom delimiter, as this is the error that you might see when the engine can't figure out how to terminate a statement:

(对于那些从搜索引擎提出这个问题的人),请检查您的存储过程是否声明了自定义分隔符,因为这是当引擎无法确定如何终止语句时您可能会看到的错误:

ERROR 1064 (42000) at line 3: 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 '' at line…

第 3 行的 ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '' at line 附近使用的正确语法...

If you have a database dump and see:

如果您有数据库转储并查看:

DROP PROCEDURE IF EXISTS prc_test;
CREATE PROCEDURE prc_test( test varchar(50))
BEGIN
    SET @sqlstr = CONCAT_WS(' ', 'CREATE DATABASE',  test, 'CHARACTER SET utf8 COLLATE utf8_general_ci');
    SELECT @sqlstr;
    PREPARE stmt FROM @sqlstr;
    EXECUTE stmt;
END;

Try wrapping with a custom DELIMITER:

尝试用 custom 包装DELIMITER

DROP PROCEDURE IF EXISTS prc_test;
DELIMITER $$
CREATE PROCEDURE prc_test( test varchar(50))
BEGIN
    SET @sqlstr = CONCAT_WS(' ', 'CREATE DATABASE',  test, 'CHARACTER SET utf8 COLLATE utf8_general_ci');
    SELECT @sqlstr;
    PREPARE stmt FROM @sqlstr;
    EXECUTE stmt;
END;
$$
DELIMITER ;

回答by Manuel

Do you have a specific database selected like so:

您是否选择了特定的数据库,如下所示:

USE database_name

Except for that I can't think of any reason for this error.

除此之外,我想不出出现此错误的任何原因。

回答by Matthias

For me I had a

对我来说,我有一个

create table mytable ( 
    dadada 
)

and forgot the semicolon at the end.

忘记了最后的分号。

So looks like this error can occur after simple syntax errors. Just like it says.. I guess you can never read the helpful compiler comments closely enough.

所以看起来这个错误可能发生在简单的语法错误之后。就像它说的那样......我想你永远不会足够仔细地阅读有用的编译器注释。

回答by Aleksandras

I had this error because of using mysql/mariadb reserved words:

由于使用了 mysql/mariadb 保留字,我遇到了这个错误:

INSERT INTO tablename (precision) VALUE (2)

INSERT INTO tablename (precision) VALUE (2)

should be

应该

INSERT INTO tablename (`precision`) VALUE (2)

INSERT INTO tablename (`precision`) VALUE (2)

回答by Monsters X

I had this, and it was the create syntax, changed to --create-options and life was better

我有这个,它是创建语法,更改为 --create-options 并且生活更好

mysqldump -u [user] -p -create-options [DBNAME] >[DumpFile].sql

And that restored nicely.

那恢复得很好。

回答by tunesmith

I ran into this once - for me, deleting all the commented out lines at the beginning of my dump file is what fixed the problem. Looks like it was a whitespace error.

我遇到过一次 - 对我来说,删除转储文件开头的所有注释行是解决问题的方法。看起来这是一个空格错误。

回答by James Cronen

Check your dump file. Looks like a stray character at the beginning. SQL isn't standard the world around, and the MySQL importer expects MySQL-friendly SQL. I'm willing to bet that your exporter did something funky.

检查您的转储文件。一开始看起来像一个流浪的角色。SQL 不是世界各地的标准,MySQL 导入程序期望 MySQL 友好的 SQL。我敢打赌你的出口商做了一些时髦的事情。

You may have to massage the file a bit to get it to work with MySQL.

您可能需要稍微调整一下文件才能使其与 MySQL 一起使用。

回答by Sanjit Majee

Finally got a solution.

终于找到了解决办法。

First .sql file converts into the UTF8.

第一个 .sql 文件转换为 UTF8。

Then use this command

然后使用这个命令

mysql -p -u root --default_character_set utf8 test </var/201535.sql

---root is the username

---root 是用户名

---test is the database name

---test 是数据库名

or

或者

mysql -p -u root test < /var/201535.sql 

---root is the username

---root 是用户名

---test is the database name

---test 是数据库名

回答by Adel Ben Hamadi

Error 1064 often occurs when missing DELIMITER around statement like : create function, create trigger.. Make sure to add DELIMITER $$ before each statement and end it with $$ DELIMITER like this:

错误 1064 经常发生在语句周围缺少 DELIMITER 时,例如:create function, create trigger.. 确保在每个语句之前添加 DELIMITER $$ 并以 $$ DELIMITER 结束它,如下所示:

DELIMITER $$
CREATE TRIGGER `agents_before_ins_tr` BEFORE INSERT ON `agents`
  FOR EACH ROW
BEGIN

END $$
DELIMITER ; 

回答by Don

If the line before your error contains COMMENT ''either populate the comment in the script or remove the empty comment definition. I've found this in scripts generated by MySQL Workbench.

如果错误之前的行包含COMMENT ''填充脚本中的注释或删除空注释定义。我在 MySQL Workbench 生成的脚本中发现了这一点。