hive 簡單shell操作

1,建表

create table test(name string );

2,查看所有表

show tables;

3,本地文件上傳

b.txt

 

haha
xiaoming
lilei
hanmeimei
 

load data local inpath '/home/b.txt' into table test;

4,查看錶數據

select * from test;

 

5,beenline

#後臺啓動metastore服務和hiveserver2服務
hive --service metastore > metastore.log 2>&1 &
hive --service hiveserver2 > hiveserver2.log 2>&1 &
或者
nohup hive --service metastore&
nohup hive --service hiveserver2&
使用beeline命令行連接:
beeline
!connect jdbc:hive2://zdh-9:10000/default
用戶名和密碼都爲空,直接回車
#成功進入beeline連接jdbc數據庫
show databases;
show tables;
#退出連接
!q
操作說明:
#連接成功,顯示一個default默認數據庫和一個student表。

 

sparkSQl shell操作

1,建表,上傳數據,都與hive完全一樣

,2,依靠ranger,實現數據脫敏

[mr@dap103-182 129-hbase-hbase-RegionServer]$ spark
spark-beeline  spark-history  sparkR         spark-shell    spark-sql      spark-submit
[mr@dap103-182 129-hbase-hbase-RegionServer]$ spark-beeline
Beeline version 1.2.1-spark2-zdh8.2.1 by Apache Hive
beeline> !connect jdbc:hive2://10.43.182.104:18000/default
Connecting to jdbc:hive2://10.43.182.104:18000/default
Enter username for jdbc:hive2://10.43.182.104:18000/default: mr
Enter password for jdbc:hive2://10.43.182.104:18000/default: **
2019-05-06 18:57:48,750 INFO org.apache.hive.jdbc.Utils: Supplied authorities: 10.43.182.104:18000
2019-05-06 18:57:48,752 INFO org.apache.hive.jdbc.Utils: Resolved authority: 10.43.182.104:18000
2019-05-06 18:57:49,221 INFO org.apache.hive.jdbc.HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2:                                       //10.43.182.104:18000/default
Connected to: Spark SQL (version 2.2.1-zdh8.2.1)
Driver: Hive JDBC (version 1.2.1-spark2-zdh8.2.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://10.43.182.104:18000/default> select * from lzz;
+------------+--+
|    name    |
+------------+--+
| haha       |
| xiaoming   |
| lilei      |
| hanmeimei  |
+------------+--+
4 rows selected (12.086 seconds)
0: jdbc:hive2://10.43.182.104:18000/default> select * from lzz;
+------------+--+
|    name    |
+------------+--+
| ****       |
| *****ing   |
| *****      |
| *****imei  |
+------------+--+
4 rows selected (2.362 seconds)
0: jdbc:hive2://10.43.182.104:18000/default>
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章