MySQL 中的错误 1064 (42000)

发布于 2024-11-28 13:41:00 字数 381 浏览 2 评论 0原文

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

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

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

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

Mysqldump 花了大约 30 分钟来显示此错误消息。

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

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

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

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

Mysqldump took about 30 minutes to display this error message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

命比纸薄 2024-12-05 13:41:01

当语句周围缺少 DELIMITER 时,通常会出现错误 1064,例如:创建函数、创建触发器。
确保在每个语句之前添加 DELIMITER $$ 并以 $$ DELIMITER 结束
像这样:

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

END $
DELIMITER ; 

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:

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

END $
DELIMITER ; 
一杆小烟枪 2024-12-05 13:41:01

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

您可能需要稍微修改该文件才能使其与 MySQL 一起工作。

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.

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

夏花。依旧 2024-12-05 13:41:01

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

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.

じ违心 2024-12-05 13:41:01

终于得到了解决方案。

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

然后使用这个命令

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

---root 是用户名

---test 是数据库名

或者

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

---root 是用户名

---test 是数据库名

Finally got a solution.

First .sql file converts into the UTF8.

Then use this command

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

---root is the username

---test is the database name

or

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

---root is the username

---test is the database name

别想她 2024-12-05 13:41:01

这是我的情况:
End of file.sql without error:添加 ' 之前 );

我忘记在 ); End of file.sql with error:

...
('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 with error: End of file.sql without error:

...
('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');

This was my case:
I forgot to add ' before );

End of file.sql with error:

...
('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:

...
('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');
人生戏 2024-12-05 13:41:01

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

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.

简单爱 2024-12-05 13:41:01

我收到这个错误

错误 1064 (42000)

,因为下载的 .sql.tar 文件因某种原因损坏。再次下载并解压就解决了这个问题。

I got this error

ERROR 1064 (42000)

because the downloaded .sql.tar file was somehow corrupted. Downloading and extracting it again solved the issue.

凉城 2024-12-05 13:41:01

在查询中进行以下更改解决了此问题:

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

请注意,列名称包含在`(选项卡上方的字符)中,而不是引号中。

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.

断桥再见 2024-12-05 13:41:01

面临同样的问题。事实上,文件开头的 SQL 是错误的,因为在转储时我做了:

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

在文件开头写了 stdout 中的内容:

mysqldump:[警告]在命令行界面上使用密码可能不安全。

导致恢复引发该错误。

因此,删除 SQL 转储的第一行可以实现正确的恢复。

查看原始问题中恢复的完成方式,很可能转储的完成方式与我的类似,导致在 SQL 文件中打印标准输出警告(如果当时 mysqldump 正在打印它)。

Faced the same issue. Indeed it was wrong SQL at the beginning of the file because when dumping I did:

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

Which wrote at the beginning of the file something that was in stdout which was:

mysqldump: [Warning] Using a password on the command line interface can be insecure.

Resulting in the restore raising that error.

So deleting the first line of the SQL dump enables a proper restore.

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).

℉服软 2024-12-05 13:41:01

当您使用mysqldump转储文件时,请使用--result-file选项而不是>运算符。

通过使用 >,输出文件将以 UTF-16 编码保存,即使您提供例如 --default-character-set=utf8mb4 > 选项。不知何故,mysql无法正确处理此编码

当您使用mysql恢复数据库时,您可以使用<加载文件

When you use mysqldump to dump file use --result-file option instead of > operator.

By using >, the output file will be saved in UTF-16 encoding even if you provide e.g --default-character-set=utf8mb4 option. Somehow this encoding can't be correctly handled by mysql

When you use mysql to restore the database you can use < to load the file

清风疏影 2024-12-05 13:41:01
ERROR 1064 (42000) at line 1:

这个错误很常见。发生此错误的主要原因是:当用户意外编辑或错误编辑.sql文件时。

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.

只想待在家 2024-12-05 13:41:00

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

第 3 行出现错误 1064 (42000):您的 SQL 语法有错误;
检查与您的 MySQL 服务器版本对应的手册
在行附近 '' 使用正确的语法...

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

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;

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

(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…

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:

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 ;
热风软妹 2024-12-05 13:41:00

您是否像这样选择了特定的数据库:

USE database_name

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

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.

最终幸福 2024-12-05 13:41:00

对我来说,我有一个

create table mytable ( 
    dadada 
)

并且忘记了最后的分号。

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

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.

楠木可依 2024-12-05 13:41:00

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

INSERT INTO tablename ( precision) VALUE (2)

应该是

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

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

INSERT INTO tablename (precision) VALUE (2)

should be

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

唠甜嗑 2024-12-05 13:41:00

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

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

而且恢复得很好。

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

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

And that restored nicely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文