启动hive:

启动hadoop:start-all.sh

启动hive:hive

[[email protected] ~]# hive

hive>

 

DDL操作:

创建表:

create命令

hive> create table student(id bigint,name string,age int);

OK

Time taken: 0.945 seconds

hive>

 

查看表:

show命令

hive> show tables;

OK

student

Time taken: 0.074 seconds,

Fetched: 1 row(s)

hive>

查看以t结尾的表:

hive> SHOW TABLES '.*t';

OK student

Time taken: 0.016 seconds,

Fetched: 1 row(s)

hive>

查看表的结构:

hive> describe student;

OK

id bigint

name string

age int

Time taken: 0.1 seconds,

Fetched: 3 row(s)

hive>

 

改变表:

alter命令

改表名:

hive> alter table student rename to stu;

加列:

hive> alter table stu add columns (birthplace string);

修改列:(没仔细研究)

hive> alter table stu replace columns (birthplace string,home string,id int,name string);

OK

Time taken: 0.246 seconds

hive>

请注意,REPLACE COLUMNS将替换所有现有列,仅更改表的架构,而不是数据。该表必须使用native SerDe。

REPLACE COLUMNS也可用于从表的模式中删除列。

 

删除表:

drop table stu;

 

元数据存储:

元数据默认存储在Derby数据库中,其磁盘存储位置在hive-site.xml中配置,javax.jdo.option.ConnectionURL。

hive——2.使用

 

 

加载数据:

1.将本地或hdfs文件中的数据加载到Hive中:

hive> LOAD DATA LOCAL INPATH'./examples/files/kv1.txt'OVERWRITE INTO TABLE pokes;

hive> LOAD DATA INPATH '/user/myname/kv2.txt' OVERWRITE INTO TABLE invites PARTITION (ds='2008-08-15');

 

 

类sql语句:

参考hive官网:

https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-RunningHiveCLI

 

 

 

遇到的错误:

1.在hive中执行sql语句报错:

SemanticException org.apache.hadoop.hive.ql.metadata.HiveException

解决:

参考:https://blog.csdn.net/xiaoqiu_cr/article/details/80913437

重新初始化元数据,再启动hive即可

[[email protected] ~]# schematool -dbType mysql -initSchema

[[email protected] ~]# hive

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-02-20
  • 2021-09-07
  • 2021-07-07
  • 2022-01-06
  • 2021-06-05
  • 2021-09-30
  • 2021-07-01
猜你喜欢
  • 2021-09-18
  • 2021-06-20
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-04-15
相关资源
相似解决方案