hive create database/table 和 hive 命令操作

来源:互联网 发布:淘宝网简介ppt 编辑:程序博客网 时间:2024/06/05 16:38
1. create database
create database db_hive_01 ;
create database if not exists db_hive_02 ;  -->   标准
create database if not exists db_hive_03 location '/user/beifeng/hive/warehouse/db_hive_03.db' ;
show databases ;
show databases like 'db_hive*' ;
use db_hive ;
desc database db_hive_01 ;
desc database extended db_hive_01 ;
drop database db_hive_01 ;
//级联删除数据库
drop database db_hive_01 cascade;

drop database if exists db_hive_01 ;

2.create table 三种方式



create table if not exists table1
(
id string comment 'id',
name string,
url string comment 'url'
)
comment 'table'
ROW FORMAT delimited fields terminated by ' '
STORED AS TEXTFILE
LOCATION '/user/hive/hive01' ;

create table if not exists table2
AS select id,name url from table1 ; 

create table if not exists table3
LIKE table1 ;


详细信息 查询

desc table1 ;
desc extended table1;
desc formatted table1


表数据的load

load data local  inpath ‘’ into table table1

清空表的数据

TRUNCATE TABLE table_name

update tablename

alter  table table1 rename to table11

drop table if exists table1

3.bin/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
 -f <filename>                    SQL from files
 -H,--help                        Print help information
 -h <hostname>                    connecting to Hive Server on remote host
    --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
 -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)


* bin/hive -e <quoted-query-string>
eg:
bin/hive -e "select * from db_hive.student ;" //不进入cli 命令


* bin/hive -f <filename>  脚本写在文件中
eg:
$ touch hivef.sql
select * from db_hive.student ;
$ bin/hive -f /opt/datas/hivef.sql  执行脚本
$ bin/hive -f /opt/datas/hivef.sql > /opt/datas/hivef-res.txt  结果写到文件中去


在hive cli命令窗口中如何查看hdfs文件系统
hive (default)> dfs -ls / ;  


在hive cli命令窗口中如何查看本地文件系统
hive (default)> !ls /opt/datas ;
                        !cat hive.sql ;

外部表和内部表的区别

http://www.aboutyun.com/thread-7458-1-1.html

0 0
原创粉丝点击