Home  >  Article  >  Database  >  Hive导入和导出数据

Hive导入和导出数据

WBOY
WBOYOriginal
2016-06-07 17:12:091838browse

hive默认的字符编码是utf8格式,所以用utf8模式存储的数据都是可以正常显示的,如果用ssh客户端工具查看时仍是乱码,这可能是你的

hive官方提供两种导入数据的方式

1 从表中导入:

insert overwrite table test

select * from test2;

2 从文件导入:

2.1 从本地文件导入:

load data local inpath '/Hadoop/aa.txt' overwrite into table test11

2.2  从hdfs导入

load data inpath '/hadoop/aa.txt' overwrite into table test11

3 导入文件的列划分

在建表的时候可以指定划分的字符 如:

create table test11(id int,name string)

row format delimited

fields terminated by '\;' 以分号划分文件的列这样导入的数据文件就如同 1;张三 这种格式。

4 到出数据

一般用 :bin/hive -e "select * from test" >> res.csv

或者:bin/hive -f sql.q >> res.csv (其中文件sql.q写入你想要执行的查询语句)

5 中文乱码问题

hive默认的字符编码是utf8格式,所以用utf8模式存储的数据都是可以正常显示的,如果用ssh客户端工具查看时仍是乱码,这可能是你的客户端工具的编码方式决定的,以secureCRT为例,修改 session options -》apperance (这样不影响其他session的编码方式),,当然 linux系统也需要做一下简单的支持utf8的设置(这个一般都支持)

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn