在所有操作前先启动hdfs、yarn、historyserver。
hive操作
-
启动hive
bin/hive -
创建数据库
create database db_hive
db_hive
-
使用数据库
use db_hive -
创建表
create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
-
查看表
show tables; -
查看表结构
1、desc students
2、desc formatted student; 推荐使用
上图Location 说明:/user/hive/warehouse 是hdfs创建的系统目录, -
加载文件数据到student表中
load data local inpath '/opt/datas/student.txt'into table student ;
-
查看可以使用的函数
show functions
![]()
-
查看某个函数
desc function extended 函数名 ;
例子:desc function extended upper;
upper
-
配置打印表头
<property>
<name>hive.cli.print.header</name>
<value>false</value>
<description>Whether to print the names of the columns in query output.</description>
</property> -
配置打印所属库
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
<description>Whether to include the current database in the Hive prompt.</description>
</property> -
退出hive eixt 重新进入。
网友评论