Hive学习笔记(1)基本操作

hive学习官方网站:
General Info
============
For the latest information about Hive, please visit out website at:
  http://hive.apache.org/

Getting Started
===============
- Installation Instructions and a quick tutorial:
  https://cwiki.apache.org/confluence/display/Hive/GettingStarted
- A longer tutorial that covers more features of HiveQL:
  https://cwiki.apache.org/confluence/display/Hive/Tutorial
- The HiveQL Language Manual:
  https://cwiki.apache.org/confluence/display/Hive/LanguageManual

1.显示数据库
show databases ;
2.创建数据库
create database db_hive ;
3. 显示表,显示表的详细信息,显示表的详细信息(格式化后),创建表
show tables ;
desc extended student ;
desc formated student ;
create table student(id int, name string) ROW FORMAT DELIMITED FIELDS
TERMINATED BY '\t' ;
4. 装载数据,最好加上数据库名
hive> load data local inpath '/opt/datas/student.txt' into
    > table db_hive.student ;
5. 查看函数,查看函数使用方法
show functions ;
desc function upper ;
6. hive中操作文件系统
dfs -ls /user/hive/warehouse ;
dfs -rm -R /user/hive/warehouse/emp;
7. 查看hive的交互命令
hive -help
usage: hive
 -d,--define <key=value>          Variable subsitution to apply to hive
                                  commands. e.g. -d A=B or --define A=B
    --database <databasename>     Specify the database to use
 -e <quoted-query-string>         SQL from command line
 例如:[root@zhangbk hadoop]# hive -e 'select * from db_hive.student ;'
 -f <filename>                    SQL from files
 例如:vi /opt/datas/hivef.sql
         select * from db_hive.student ;
      [root@zhangbk datas]# hive -f /opt/datas/hivef.sql
  也可将查询结果写入文件:[root@zhangbk datas]# hive -f /opt/datas/hivef.sql > /opt/datas/hivef.txt
 -h <hostname>                    connecting to Hive Server on remote host
 -H,--help                        Print help information
    --hiveconf <property=value>   Use value for given property
    --hivevar <key=value>         Variable subsitution to apply to hive
                                  commands. e.g. --hivevar A=B
 -i <filename>                    Initialization SQL file
 例如:与用户自定义的udf相互使用。
 -p <port>                        connecting to Hive Server on port number
 -S,--silent                      Silent mode in interactive shell
 -v,--verbose                     Verbose mode (echo executed SQL to the
                                  console)
8. 交互命令hive cli
exit/quit ;
dfs -ls / ;
!ls ;查看操作系统本地的文件

猜你喜欢

转载自blog.csdn.net/weixin_43241054/article/details/90146712
今日推荐