试一试:
SELECT hour_stamp,
day_stamp,
month_stamp,
hour,
day,
month,
year,
quarter,
day_of_week,
week_of_year,
SUBSTR(hour_text,1,24),
SUBSTR(day_text,1,24)
FROM date_dim
INTO OUTFILE '/media/ssd0/temp/dates.tsv';
这是一个示例
mysql> desc veto.prova;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| provaemail | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
2 rows in set (0.05 sec)
mysql> select * from veto.prova;
+----+--------------------------+
| id | provaemail |
+----+--------------------------+
| 1 | redwards@logicworks.net |
| 2 | rolandoedwards@yahoo.com |
+----+--------------------------+
2 rows in set (0.00 sec)
mysql> select id,provaemail from prova into outfile 'C:/lwdba/prova.txt';
Query OK, 2 rows affected (0.01 sec)
mysql>
它在磁盘上是什么样的???
C:\>cd lwdba
C:\LWDBA>type prova.txt
1 redwards@logicworks.net
2 rolandoedwards@yahoo.com
C:\LWDBA>
我尝试了一些奇怪的东西。我终止了\0
mysql> select id,provaemail,substr(provaemail,1,5) from prova into outfile 'C:/lwdba/prova9.txt' fields terminated by '\0';
Query OK, 2 rows affected, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Warning | 1475 | First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select id,provaemail,substr(provaemail,1,5) from prova into outfile 'C:/lwdba/prova8.txt' fields enclosed by '\0';
Query OK, 2 rows affected (0.00 sec)
mysql>
文件如下所示:
C:\LWDBA>type prova9.txt
1 redwards@logicworks.net redwa
2 rolandoedwards@yahoo.com rolan
C:\LWDBA>type prova8.txt
1 redwards@logicworks.net redwa
2 rolandoedwards@yahoo.com rolan
C:\LWDBA>
我使用\0
它是因为它是一个空字符。
您看到的双引号异常可能是由于 InfoBright 存储引擎以及它如何呈现函数调用的字符输出。
这是一个奇怪的建议,但我不知道它是否会起作用......
如果您进行子查询,则数据始终存储在 MySQL 临时表中。更改查询:
mysql> select * from (select id,provaemail,substr(provaemail,1,5) as stuff from prova) A
-> A into outfile 'C:/lwdba/prova444.txt' fields terminated by '\0' enclosed by '\0';
Query OK, 2 rows affected (0.00 sec)
mysql>
在你的情况下,那将是
SELECT * FROM (
SELECT hour_stamp,
day_stamp,
month_stamp,
hour,
day,
month,
year,
quarter,
day_of_week,
week_of_year,
SUBSTR(hour_text,1,24) ht,
SUBSTR(day_text,1,24) dt
FROM date_dim) A
INTO OUTFILE '/media/ssd0/temp/dates.tsv';
看看这是否有不同的作用