hive create database/table 和 hive 命令操作

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

### 创建 Hive 行存储表 在 Hive 中创建行存储表涉及定义表结构以及指定数据位置。以下是创建行存储表的标准 SQL 语句: ```sql CREATE TABLE IF NOT EXISTS database_name.table_name ( column1 datatype, column2 datatype, ... ) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE; ``` 此命令用于创建一个简单的行存储表,其中 `ROW FORMAT` `STORED AS` 子句指定了文件的格式分隔符[^1]。 对于更复杂的场景,可以添加分区或桶化来优化查询性能: #### 使用分区 当数据可以根据某些列进行逻辑划分时,建议使用分区以提高查询效率: ```sql CREATE TABLE IF NOT EXISTS sales_data ( order_id BIGINT, customer_id STRING, product_code STRING, quantity INT ) PARTITIONED BY (year INT, month INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS ORC; ``` 上述例子展示了如何基于年份月份对销售记录进行分区,并采用逗号作为字段间的分隔符。 #### 应用压缩技术 为了减少磁盘占用并加快读取速度,在创建表时可以选择不同的存储格式支持压缩的方式: ```sql CREATE TABLE web_logs ( ip STRING, timestamp STRING, request STRING, status STRING, size STRING ) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' WITH SERDEPROPERTIES ('field.delim'='\u0001') STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.SequenceFileInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'; ``` 这段代码片段说明了通过设置特定序列化的输入/输出格式来进行高效的数据处理。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值