(请参阅下面的答案。如果它能帮助其他人,请将其保留下来。)
以下是一系列尝试将查询转储到我的网站已迁移到的新FreeBSD框上的outfile。如果我以我的身份登录或以root用户身份登录,结果是一样的。我希望风格不会太烦人。我的评论围绕实际的代码和输出进行了评论。
//尝试将查询转储到我的主目录
SELECT pmr.datetime_requested,
nfo.postal_code
FROM
print_mailing_request pmr,
personal_info nfo
WHERE
nfo.person = pmr.person AND
pmr.datetime_requested >= "2010-01-01 00:00:00" AND
(pmr.print_mailing = 31 OR pmr.print_mailing = 30)
ORDER BY pmr.datetime_requested INTO OUTFILE '/usr/home/david/x';
ERROR 1 (HY000): Can't create/write to file '/usr/home/david/x' (Errcode: 2)
//尝试使用touch创建文件,甚至是chmod 077文件 //但每次都有相同的错误
//好的,让我们试试/ tmp
SELECT pmr.datetime_requested,
nfo.postal_code
FROM
print_mailing_request pmr,
personal_info nfo
WHERE
nfo.person = pmr.person AND
pmr.datetime_requested >= "2010-01-01 00:00:00" AND
(pmr.print_mailing = 31 OR pmr.print_mailing = 30)
ORDER BY pmr.datetime_requested INTO OUTFILE '/tmp/x';
Query OK, 24654 rows affected (0.78 sec)
//让我们看一下文件
less /tmp/x
/tmp/x: No such file or directory
//重新登录mysql并再次尝试相同的查询
ERROR 1086 (HY000): File '/tmp/x' already exists
ls /tmp
20100325180233.gtg2010.csv 20100330094652.gtg2010.csv
20100325180448.gtg2010.csv 2010_Q1_UNO.csv
20100325181446.gtg2010.csv 4724.csv
20100325181927.gtg2010.csv aprbUfvxp
20100326003002.gtg2010.csv dave.txt
20100327003002.gtg2010.csv etr.xml
20100328003002.gtg2010.csv mysql.sock
20100329003003.gtg2010.csv
//没有文件x。
//如果我在没有INTO OUTFILE的情况下运行查询,我会看到24000多行
| 2010-04-04 13:27:09 | 33156 |
| 2010-04-04 13:27:10 | 33156 |
| 2010-04-04 13:30:04 | NE38 8SR |
| 2010-04-04 14:27:03 | 00901 |
| 2010-04-04 14:37:04 | 75001 |
| 2010-04-04 14:53:05 | 78640 |
| 2010-04-04 15:15:03 | 07410 |
| 2010-04-04 15:27:04 | 43235 |
//所以我知道这不是查询...
//建议?
答案 0 :(得分:0)
卫生署!当我在这台机器上登录mysql时,我的连接字符串中有一个IP地址。 / tmp就mysql而言,我登录的机器上没有...
所以我使用mysql -e
来解决问题,例如:
mysql -h my.db.com -u usrname--password=pass db_name -e 'SELECT foo FROM bar' > /tmp/myfile.txt