使用 SELECT INTO OUTFILE 时出现语法错误
以下查询时
SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;
当我运行直接来自 MySQL 文档的 ,出现语法错误。我没有 test_table
表,并且我知道该语句实际上不起作用,但它似乎不应该给出语法错误。如果我直接从 MySQL 文档中得到语法错误,可能会发生什么情况?
这是我正在看的文档(5.1): http://dev.mysql.com/doc/refman/5.1/en /select.html
这是我的 MySQL 版本:
mysql Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i686) using readline 6.1
When I run the following query
SELECT a,b,a+b INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;
which is straight from the MySQL documentation, I get a syntax error. I don't have a test_table
table and I understand that this statement won't actually work, but it doesn't seem like it should give a syntax error. If I'm getting a syntax error on something straight from the MySQL documentation, what could be going on?
This is the doc I'm looking at (5.1):
http://dev.mysql.com/doc/refman/5.1/en/select.html
This is my MySQL version:
mysql Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i686) using readline 6.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码对我有用。
起初,我遇到了
Unknown table 'test_table' in my_db
错误。创建表
CREATE TABLE test_table (a VARCHAR(255), b VARCHAR(255))
后,它就正常工作了。没有语法错误。编辑:
从官方
mysql
命令行客户端运行查询可以避免 GUI 客户端中潜在的错误,并提供更准确的错误消息。This code works for me.
At first I had an
Unknown table 'test_table' in my_db
error.After creating the table
CREATE TABLE test_table (a VARCHAR(255), b VARCHAR(255))
it just worked. No syntax error.Edit:
Running the query from the official
mysql
command line client can avoid potential bugs in your GUI client and give more accurate error messages.也许您必须根据您使用的语言转义某些字符。
示例:
Maybe you have to escape some of the characters depending on the language you are using.
php example: