查看当前所有数据库
show databases;
使用特定数据库
use databasename; 例如:use open_011_dwd;
创建表
create table tmp_epm20210115_liangzf02_no_par (empno int comment '员工电话', ename string comment '员工姓名', job string comment '职位', mgr string comment '工资', hiredate string, sal string, comm int, deptno int) row fromat delimited fields terminated by ',';
删除表
drop table tableName; 示例:drop table open_011_dwd.tmp_epm20210115_liangzf01;
创建分区表
create table open_011_dwd.tmp_epm20210115_liangzf01 (empno int, ename string, job string, mgr int, hiredate string, sal int,c comm int, deptno int) PARTITIONED BY ( month_part int COMMENT '月分区', day_part int COMMENT '日分区' ) row format delimited fields terminated by ',';
加载数据
加载数据的三种方式:1 alter table open_011_dwd.tmp_epm20210115_liangzf01 add partition (month_part=202101,day_part=19) location '/user/hive/wangyun_oss/test_20210119_emp.txt'; 加载数据的三种方式:2,底层mv文件,原始文件删除 load data inpath '/user/hive/user_bonc/tmp/liangzf/test_20210119_emp.txt' into table open_011_dwd.tmp_epm20210115_liangzf01 partition ( month_part=202101,day_part=19); 加载数据的三种方式:3
create table open_011_dwd.tmp_epm20210115_liangzf02 like open_011_dwd.tmp_epm20210115_liangzf01;--创建一张完全同结构的表 create table open_011_dwd.tmp_epm20210115_liangzf03 as select t.empno,t.ename,t.job,t.mgr,t.hiredate,t.sal,t.comm,t.deptno from open_011_dwd.tmp_epm20210115_liangzf01 t; insert into table open_011_dwd.tmp_epm20210115_liangzf03 select t.empno,t.ename,t.job,t.mgr,t.hiredate,t.sal,t.comm,t.deptno from open_011_dwd.tmp_epm20210115_liangzf01 t; insert overwrite table open_011_dwd.tmp_epm20210115_liangzf03 select t.empno,t.ename,t.job,t.mgr,t.hiredate,t.sal,t.comm,t.deptno from open_011_dwd.tmp_epm20210115_liangzf01 t;
数据清理
--数据清理 truncate table open_011_dwd.tmp_epm20210115_liangzf03; alter table open_011_dwd.tmp_epm20210115_liangzf01 delete partition (month_part=202101,day_part=19);
查询数据量
select count(*) from open_011_dwd.tmp_epm20210115_liangzf01 t where month_part=202101 and day_part=19;
数据导出
--数据导出1 insert overwrite directory '/user/hive/user_bonc/tmp/liangzf/tmp20210119' select * from open_011_dwd.tmp_epm20210115_liangzf01 t where month_part=202101 and day_part=19; --数据导出2 beeline -u 'jdbc:hive2://hb-db-nn-001:2181,hb-db-nn-002:2181,hb-db-dn-001:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2?mapreduce.job.queuename=queue_bonc' -n user_bonc -p lpfD@d92 --silent=true --showHeader=false beeline -u 'jdbc:hive2://hb-db-nn-001:2181,hb-db-nn-002:2181,hb-db-dn-001:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2?mapreduce.job.queuename=queue_bonc' -n user_bonc -p lpfD@d92 beeline -u 'jdbc:hive2://hb-db-nn-001:2181,hb-db-nn-002:2181,hb-db-dn-001:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2?mapreduce.job.queuename=queue_bonc' -n user_bonc -p lpfD@d92 --silent=true --showHeader=false --outputformat=dsv -e "select t.* from open_011_dwd.tmp_epm20210115_liangzf01 t where month_part=202101 and day_part=19;" > /data/tmp/liangzf_tmp/test_output_emp_20210119.txt