MySQL(5.6) "select * into outfile.." 没有创建文件

MySQL(5.6) "select * into outfile.." not creating files

当我以 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 命令行 运行 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;