https://github.com/zq2599/blog_demosnode
內容:全部原創文章分類彙總及配套源碼,涉及Java、Docker、Kubernetes、DevOPS等;git
create database if not exists test comment 'this is a database for test';
hive> show databases like 't*'; OK test test001 Time taken: 0.016 seconds, Fetched: 2 row(s)
hive> describe database test; OK test this is a database for test hdfs://node0:8020/user/hive/warehouse/test.db hadoop USER Time taken: 0.035 seconds, Fetched: 1 row(s)
5. 新建數據庫的文件夾都在/user/hive/warehouse下面,這是在中配置的,以下圖紅框:程序員
6. 刪除數據庫,加上if exists,當數據庫不存在時,執行該語句不會返回Error:github
hive> drop database if exists test; OK Time taken: 0.193 seconds
以上就是經常使用的庫相關操做,接下來實踐表相關操做;web
create table t6(id int, name string) row format delimited fields terminated by ',';
insert into t6 values (101, 'a101');
[hadoop@node0 bin]$ ./hadoop fs -ls /user/hive/warehouse/t6 Found 1 items -rwxr-xr-x 3 hadoop supergroup 9 2020-10-31 11:14 /user/hive/warehouse/t6/000000_0
[hadoop@node0 bin]$ ./hadoop fs -cat /user/hive/warehouse/t6/000000_0 101 a101
[hadoop@node0 bin]$ ./hadoop fs -ls /user/hive/warehouse/ Found 5 items drwxr-xr-x - hadoop supergroup 0 2020-10-27 20:42 /user/hive/warehouse/t1 drwxr-xr-x - hadoop supergroup 0 2020-10-29 00:13 /user/hive/warehouse/t2 drwxr-xr-x - hadoop supergroup 0 2020-10-29 00:14 /user/hive/warehouse/t3 drwxr-xr-x - hadoop supergroup 0 2020-10-29 13:04 /user/hive/warehouse/t4 drwxr-xr-x - hadoop supergroup 0 2020-10-29 16:47 /user/hive/warehouse/t5
create external table t7(id int, name string) row format delimited fields terminated by ',' location '/data/external_t7';
[hadoop@node0 bin]$ ./hadoop fs -ls /data/ Found 1 items drwxr-xr-x - hadoop supergroup 0 2020-10-31 12:02 /data/external_t7
insert into t7 values (107, 'a107');
[hadoop@node0 bin]$ ./hadoop fs -ls /data/external_t7 Found 1 items -rwxr-xr-x 3 hadoop supergroup 9 2020-10-31 12:06 /data/external_t7/000000_0 [hadoop@node0 bin]$ ./hadoop fs -cat /data/external_t7/000000_0 107,a107
create external table t8(id_t8 int, name_t8 string) row format delimited fields terminated by ',' location '/data/external_t7';
hive> select * from t8; OK 107 a107 Time taken: 0.068 seconds, Fetched: 1 row(s) hive> select * from t7; OK 107 a107 Time taken: 0.074 seconds, Fetched: 1 row(s)
hive> drop table t7; OK Time taken: 1.053 seconds hive> select * from t8; OK 107 a107 Time taken: 0.073 seconds, Fetched: 1 row(s)
[hadoop@node0 bin]$ ./hadoop fs -cat /data/external_t7/000000_0 107,a107
create table t8(id int, name string) row format delimited fields terminated by ',';
alter table t8 rename to t8_1;
hive> alter table t8 rename to t8_1; OK Time taken: 0.473 seconds hive> show tables; OK alltype t1 t2 t3 t4 t5 t6 t8_1 values__tmp__table__1 values__tmp__table__2 Time taken: 0.029 seconds, Fetched: 10 row(s)
alter table t8_1 add columns(remark string);
查看錶結構,可見已經生效:sql
hive> desc t8_1; OK id int name string remark string Time taken: 0.217 seconds, Fetched: 3 row(s)
至此,我們對內部表和外部表已經有了基本瞭解,接下來的文章學習另外一種常見的表類:分區表;shell
微信搜索「程序員欣宸」,我是欣宸,期待與您一同暢遊Java世界...
https://github.com/zq2599/blog_demos數據庫