如何在Hive上建表并导入数据

时间:2022-02-22 00:14:51
  1. 上传数据文件到HDFS
    hdfs dfs -put data /tmp/

  2. 运行hive命令,打开hive终端
    https://cwiki.apache.org/confluence/display/Hive/LanguageManual

  3. 建表
    create table test_1 (id string, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,’;
    上面建表语句的意思是:每一行以逗号’,’为分隔符,每行有两列,分别为id 和 name

  4. load data inpath ‘/tmp/data’ into table test_1;

hive中常用命令:
1. show databases;
2. show tables;
3. use ‘database name’ //切换到某个数据库