当我以 root 用户身份在本地主机上使用此命令时,它可以毫无问题地运行,但我似乎找不到实际文件。
SELECT * INTO OUTFILE 'C:\...\tableName.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
FROM tableName;
当我尝试再次运行查询时,它说文件已经创建,即使它显然不是。
编辑:修复了我的查询语法
当我以 root 用户身份在本地主机上使用此命令时,它可以毫无问题地运行,但我似乎找不到实际文件。
SELECT * INTO OUTFILE 'C:\...\tableName.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
FROM tableName;
当我尝试再次运行查询时,它说文件已经创建,即使它显然不是。
编辑:修复了我的查询语法
在FROM
你的*
. 您的查询应该看起来更像这样:
SELECT * INTO OUTFILE 'C:\...\tableName.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\r\n'
FROM tableName;
注意:确保mysql有写入权限'C:\...\tableName.txt'
至于文件已经创建错误:
该文件可能是在mysql实际有权写入的另一个目录中创建的,例如数据目录。这就是为什么您在多次运行查询后收到文件已创建的消息的原因。
从 mysql 命令行 run show variables like '%dirdata%';
,您应该会看到类似于以下内容的输出:
mysql> show variables like '%datadir%';
+---------------+-------------------------------------+
| Variable_name | Value |
+---------------+-------------------------------------+
| datadir | c:\wamp\bin\mysql\mysql5.6.17\data\ |
+---------------+-------------------------------------+
1 row in set (0.35 sec)
在 Windows 中导航到该文件夹,您应该在那里找到您的文件。
SELECT r INTO OUTFILE 'c:\dev\myA2.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM a2;
-- leads me to believe it works first time with rowcount output
-- but it does not put file in dev
-- run it again it says error 1086: File 'c:devmyA2.txt' already exists
so that means it wrote it to c:
the default of what mysql query engine has for c: at that time
I did not hunt for it !
the following works great (note the double slashes \\):
SELECT r INTO OUTFILE 'c:\\dev\\drew_so_answers\\myA2.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM a2;