简体   繁体   English

MySQL中的错误1064(42000)

[英]ERROR 1064 (42000) in MySQL

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数据库创建的数据库转储填充新的MySQL空数据库,我收到以下错误

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; 第1行的错误1064(42000):SQL语法中有错误; Check the manual that corresponds to your MySQL server version for the right syntax to use near 'I ' at line 1 检查与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分钟来显示此错误消息。

(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; 错误1064(42000)在第3行:您的SQL语法中有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line… 查看与您的MySQL服务器版本对应的手册,以便在''在线附近使用正确的语法...

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 : 尝试使用自定义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 ;

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. 除此之外,我无法想到出现此错误的任何原因。

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. 就像它说..我想你永远不能仔细阅读有用的编译器评论。

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. 而那恢复得很好。

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是数据库名称

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 ; 

I had this error because of using mysql/mariadb reserved words: 我有这个错误,因为使用mysql / mariadb保留字:

INSERT INTO tablename (precision) VALUE (2)

should be 应该

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

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. SQL不是世界的标准,MySQL导入器需要MySQL友好的SQL。 I'm willing to bet that your exporter did something funky. 我愿意打赌你的出口商做了一些时髦的事情。

You may have to massage the file a bit to get it to work with MySQL. 您可能需要按一下文件才能使它与MySQL一起使用。

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. 看起来这是一个空白错误。

This was my case: I forgot to add ' before ); 这是我的情况:我忘了添加'之前);

End of file.sql with error: file.sql结束,错误:

...
('node','ad','0','3879','3879','und','0','-14.30602','-170.696181','0','0','0'),
('node','ad','0','3880','3880','und','0','-14.30602','-170.696181','0','0','0);

End of file.sql without error: file.sql结束,没有错误:

...
('node','ad','0','3879','3879','und','0','-14.30602','-170.696181','0','0','0'),
('node','ad','0','3880','3880','und','0','-14.30602','-170.696181','0','0','0');

If the line before your error contains COMMENT '' either populate the comment in the script or remove the empty comment definition. 如果错误之前的行包含COMMENT '' ,则填充脚本中的注释或删除空注释定义。 I've found this in scripts generated by MySQL Workbench. 我在MySQL Workbench生成的脚本中找到了这个。

I got this error 我收到了这个错误

ERROR 1064 (42000) 错误1064(42000)

because the downloaded .sql.tar file was somehow corrupted. 因为下载的.sql.tar文件以某种方式被破坏了。 Downloading and extracting it again solved the issue. 再次下载和解压缩解决了这个问题。

Making the following changes in query solved this issue: 在查询中进行以下更改解决了此问题:

INSERT INTO table_name (`column1`, `column2`) values ('val1', 'val2');

Note that the column names are enclosed in ` (character above tab) and not in quotes. 请注意,列名称括在`(选项卡上方的字符)而不是引号中。

Faced the same issue. 面对同样的问题。 Indeed it was wrong SQL at the beginning of the file because when dumping I did: 事实上,在文件开头是错误的SQL,因为在转储时我做了:

mysqldump -u username --password=password db_name > dump.sql

Which wrote at the beginning of the file something that was in stdout which was: 哪个在文件的开头写了一些在stdout中的内容:

mysqldump: [Warning] Using a password on the command line interface can be insecure. mysqldump:[警告]在命令行界面上使用密码可能不安全。

Resulting in the restore raising that error. 导致恢复提高该错误。

So deleting the first line of the SQL dump enables a proper restore. 因此,删除SQL转储的第一行可以进行正确的还原。

Looking at the way the restore was done in the original question, there is a high chance the dump was done similarly as mine, causing a stdout warning printing in the SQL file (if ever mysqldump was printing it back then). 看看原始问题中恢复的方式,转储的可能性与我的相似,导致在SQL文件中打印stdout警告(如果mysqldump正在打印它的话)。

ERROR 1064 (42000) at line 1:

This error is very common. 这个错误很常见。 The main reason of the occurrence of this error is: When user accidentally edited or false edit the .sql file. 发生此错误的主要原因是:当用户意外编辑或错误编辑.sql文件时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM