MySQL的密码是:123456
1、hive创建标准表(以后均可以按照这样创建):
create table records (year STRING,temperature INT,quality INT)
row format delimted
fields terminated by ‘\t’;
解析:第一行声明一个records表,包括三列(3个字段):year,temperature,quality。分别指定数据类型为:string,int,int。//第一行解析与MySQL创建表一样
第二行是HiveQL所特有,数据文件中每一行都是由制表符分隔的文本。若将文本导入由本地或者hdfs导入hive时必须按照此格式即每行三个字段,每个字段由制表符分隔,每行由换行符分隔
注意:row format delimted 分隔符设置的开始语句
fields terminated by ‘\t’ 设置字段与字段之间的分隔符,此时使用制表符分隔
collection items terminated by "." 设置一个复杂类型(array,struct)字段中的各个item之间的分隔符,此时用点表示
map keys terminated by "." 设置复杂类型map字段的key和value之间的分隔符,此时用电表示
lines terminated by 设置行与行之间的分隔符
例如:row format delimited
fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':'
lines terminated by '\n';
OK
Time taken: 0.287 seconds
ROW FORMAT DELIMITED 必须在其它分隔设置之前,也就是分隔符设置语句的最前
LINES TERMINATED BY必须在其它分隔设置之后,也就是分隔符设置语句的最后,否则会报错
PS:表名records在hdfs中其实是目录名;
2、将数据文件导入hive
load data local inpath “/home/hdc/sample.txt”
overwrite into table records;
解析:将本地文件sample导入records表中,其中overwrite可加可不加,如果加表示hive删除表对应目录中已有的所有文件,再将sample.txt文件送到records下;
若不加表示hive简单的把sample.txt文件加入目录(若此目录有同名的文件则替换)。
3、--将HDFS中 /input/student.txt 导入到t3
load data inpath '/input/student.txt' overwrite into table t3;
4、将数据导入分区表:
load data local inpath '/home/hdc/data_1.txt' into table partition_table partition(gender='M');