Mysql ERROR 第 1153 行:未知命令 '\'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5888589/
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
Mysql ERROR at line 1153: Unknown command '\'
提问by Chris
I am trying to import a mysqldump file via the command line, but continue to get an error. I dumped the file from my other server using:
我正在尝试通过命令行导入一个 mysqldump 文件,但继续出现错误。我使用以下方法从其他服务器转储了文件:
mysqldump -u XXX -p database_name > database.sql
Then I try to import the file with:
然后我尝试导入文件:
mysql -u XXX -p database_name < database.sql
It loads a small portion and then gets stuck. The error I receive is:
它加载了一小部分然后卡住了。我收到的错误是:
ERROR at line 1153: Unknown command '\''.
I checked that line in the file with:
我检查了文件中的那一行:
awk '{ if (NR==1153) print mysql -u[USERNAME] -p[PASSWORD] --default-character-set=latin1
[DATABASE_NAME] < [BACKUP_SQL_FILE.sql]
}' database.sql >> line1153.sql
and it happens to be over 1MB in size, just for that line.
它的大小恰好超过 1MB,仅用于该行。
Any ideas what might be going on here?
任何想法可能会发生什么?
回答by miker
You have binary blobs in your DB, try adding --hex-blob to your mysqldump statement.
您的数据库中有二进制 blob,请尝试将 --hex-blob 添加到您的 mysqldump 语句中。
回答by Alain Collins
You know what's going on - you have an extra single quote in your SQL!O
你知道发生了什么 - 你的 SQL 中有一个额外的单引号!O
If you have 'awk', you probably have 'vi', which will open your line1153.sql file with ease and allow you to find the value in your database that is causing the problem.
如果你有'awk',你可能有'vi',它会很容易地打开你的line1153.sql 文件,并允许你在你的数据库中找到导致问题的值。
Or... The line is probably large because it contains multiple rows. You could also use the --skip-extended-insert
option to mysqldump so that each row got a separate insert statement.
或者... 该行可能很大,因为它包含多行。您还可以使用--skip-extended-insert
mysqldump 选项,以便每一行都有一个单独的插入语句。
Good luck.
祝你好运。
回答by P.C.
I had the same problem because I had Chinese characters in my datasbase. Below is what I found from some Chinese forum and it worked for me.
我遇到了同样的问题,因为我的数据库中有汉字。下面是我从一些中文论坛上找到的,它对我有用。
Array
(
[type] => 1
[message] => Maximum execution time of 300 seconds exceeded
[file] => C:\xampp\htdocs\openemr\phpmyadmin\libraries\Util.class.php
[line] => 296
)
回答by jimmy5
I think you need to use path/to/file.sql
instead of path\to\file.sql
我认为你需要使用path/to/file.sql
而不是path\to\file.sql
Also, database < path/to/file.sql
didn't work for me for some reason - I had to use use database;
and source path/to/file.sql;
.
此外,database < path/to/file.sql
由于某种原因对我不起作用 - 我不得不使用use database;
和source path/to/file.sql;
.
回答by Growling Flea
I recently had a similar problem where I had done an sql dump on a Windows machine and tried to install it on a Linux machine. I had a fairly large SQL file and my error was happening at line 3455360. I used the following command to copy all text up to the point where I was getting an error:
我最近遇到了一个类似的问题,我在 Windows 机器上做了一个 sql 转储,并试图将它安装在 Linux 机器上。我有一个相当大的 SQL 文件,我的错误发生在第 3455360 行。我使用以下命令将所有文本复制到出现错误的位置:
sed -n '1, 3455359p' < sourcefile.sql > destinationfile.sql
sed -n '1, 3455359p' <sourcefile.sql> destinationfile.sql
This copied all the good code into a destination file. I looked at the last few lines of the destination file and saw that it was a complete SQL command (The last line ended with a ';') so I imported the good code and didn't get any errors.
这将所有好的代码复制到目标文件中。我查看了目标文件的最后几行,发现它是一个完整的 SQL 命令(最后一行以“;”结尾),因此我导入了正确的代码并且没有出现任何错误。
I then looked at the rest of the file which was about 20 lines. It turns out that the export might not have completed b/c I saw the following php code at the end of the code:
然后我查看了文件的其余部分,大约 20 行。结果是导出可能没有完成 b/c 我在代码末尾看到了以下 php 代码:
sed 's._\._\\.g' dump.sql > dump2.sql
I removed the offending php code and imported the rest of the database.
我删除了有问题的 php 代码并导入了数据库的其余部分。
回答by Ehsan Chavoshi
I had special character in table names , like _\
and it give error when try to import that tables.
i fixed it by changing \
to \\
in dumped sql.
my table names where like rate_\
and i used this command to repair dump :
我在表名中有特殊字符,例如_\
尝试导入该表时出错。我通过在转储的 sql 中更改\
为来修复它\\
。我的表名在哪里rate_\
,我用这个命令来修复转储:
Unknown command '\?'.
i didn't replace all backslashes , because i was not sure if there is some backslash somewhere in database that should not be replaces.
我没有替换所有反斜杠,因为我不确定数据库中是否有一些不应该替换的反斜杠。
special characters in table name will be converted to @ at sign in file name. read http://dev.mysql.com/doc/refman/5.5/en/identifier-mapping.html
表名中的特殊字符将在登录文件名时转换为@。阅读http://dev.mysql.com/doc/refman/5.5/en/identifier-mapping.html
回答by Pugal
I have same error as,
我有同样的错误,
mysql -u root -p trainee < /xx/yy.gz
when I ran this
当我运行这个
mysql -u root -p trainee < /xx/yy.sql
So I'd followed these answers. But I did not got the restored db trainee
. Then found that
yy.gz
is zip
file. So I restoring after unzip the file as:
所以我遵循了这些答案。但我没有得到恢复的 db trainee
。然后发现
yy.gz
是zip
文件。所以我在解压文件后恢复为:
回答by john elemans
If all else fails, use MySQLWorkbench to do the import. This solved the same problem for me.
如果所有其他方法都失败了,请使用 MySQLWorkbench 进行导入。这为我解决了同样的问题。