ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # 1. Hive客户端 **1. 进入hive客户端工具** ```shell [root@hadoop101 /]# hive ``` <br/> **2. 查看所有数据库** ```sql hive> show databases; ``` <br/> **3. 查看当前使用的数据库** ```sql hive> select current_database(); ``` <br/> **4. 查看当前数据库的所有数据表** ```sql hive> show tables; ``` <br/> **5. 查看hive_table表的描述信息** ```sql hive> desc hive_table; ``` <br/> **6. 执行Linux命令** ```sql hive> !ls /; bin boot data ``` <br/> **7. 执行hdfs命令** ```sql hive> dfs -ls /; drwxr-xr-x - root supergroup 0 2021-04-23 04:57 /hbase drwxrwxrwx - root supergroup 0 2021-03-04 03:33 /home ``` <br/> **8. 执行new_sql.sql文件** ```sql hive> source /opt/install/hive/mydata/new_sql.sql; ``` <br/> **9. 查看hive版本信息** ```sql hive> !hive --version; Hive 1.1.0-cdh5.14.2 ``` <br/> **10. 退出hive客户端,执行 quit; 或者按Ctrl+C** ```sql hive> quit; ``` <br/> # 2. beeline客户端 **1. 使用beeline客户端需要提前开启hiveserver2服务** ```shell -- 开启方式1:该方式启动会打印日志 [root@hadoop101 /]# hiveserver2 -- 开启方式2:该方式启动不会打印日志 [root@hadoop101 /]# nohup hive --service hiveserver2 & -- 开启方式3:先开启元数据服务器(这一步是非必须的),再开启hiveserver2 [root@hadoop101 /]# nohup hive --service metastore & [root@hadoop101 /]# nohup hive --service hiveserver2 & ``` <br/> **2. 进入beeline客户端工具** ```shell ### 进入方式1 ### [root@hadoop101 /]# beeline -- 10000 hive默认的连接端口 beeline> !connect jdbc:hive2://hadoop101:10000 -- root hdfs中Owner属性的值,当你创建数据库/表时为root拥有,如果直接回车默认为匿名用户:anonymous Enter username for jdbc:hive2://hadoop101:10000: root -- 我没有为hdfs设置密码,直接回车即可 Enter password for jdbc:hive2://hadoop101:10000: ### 进入方式2 ### [root@hadoop101 /]# bin/beeline -u "jdbc:hive2://hadoop101:10000" -n "root" -p "" ``` <br/> **3. 查看当前使用的数据库** ```sql 0: jdbc:hive2://hadoop101:10000> select current_database(); +----------+--+ | _c0 | +----------+--+ | default | +----------+--+ ``` <br/> **4. 查看当前数据库的数据表** ```sql 0: jdbc:hive2://hadoop101:10000> !tables +------------+---------------+--------------------------+-------------+ | TABLE_CAT | TABLE_SCHEM | TABLE_NAME | TABLE_TYPE | +------------+---------------+--------------------------+-------------+ | | sales_rds | customer | TABLE | | | sales_rds | product | TABLE | ``` <br/> **5. 查看hive_table表的描述信息** ```sql 0: jdbc:hive2://hadoop101:10000> !column hive_table ``` <br/> **6. 执行Linux命令** ```sql 0: jdbc:hive2://hadoop101:10000> !sh ls / bin boot data ``` <br/> **7. 执行hdfs命令** ```sql 0: jdbc:hive2://hadoop101:10000> dfs -ls /; +----------------------------------------------------+--+ | DFS Output | +----------------------------------------------------+--+ | drwxr-xr-x - root supergroup 0 2021-03-09 18:59 /event | | drwxr-xr-x - root supergroup 0 2021-04-23 04:57 /hbase | | drwxrwxrwx - root supergroup 0 2021-03-04 03:33 /home | ``` <br/> **8. 执行new_sql.sql文件** ```sql 0: jdbc:hive2://hadoop101:10000> !run /opt/install/hive/mydata/new_sql.sql ``` <br/> **9. 查看Hive版本信息** ```sql 0: jdbc:hive2://hadoop101:10000> !dbinfo getDatabaseProductName Apache Hive getDatabaseProductVersion 1.1.0-cdh5.14.2 ``` <br/> **10. 退出hive客户端,执行 !quit 或者按Ctrl+C** ```sql 0: jdbc:hive2://hadoop101:10000> !quit ``` **11. 去掉烦人的INFO信息** ```sql -- 未去掉前 0: jdbc:hive2://hadoop101:10000> show databases; INFO : Compiling command(queryId=root_20201208193434_971c2ddd-b798-40f7-9847-fb3d0675bef4): show databases INFO : Semantic Analysis Completed INFO : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:database_name, type:string, comment:from deserializer)], properties:null) INFO : Completed compiling command(queryId=root_20201208193434_971c2ddd-b798-40f7-9847-fb3d0675bef4); Time taken: 0.042 seconds INFO : Concurrency mode is disabled, not creating a lock manager INFO : Executing command(queryId=root_20201208193434_971c2ddd-b798-40f7-9847-fb3d0675bef4): show databases INFO : Starting task [Stage-0:DDL] in serial mode INFO : Completed executing command(queryId=root_20201208193434_971c2ddd-b798-40f7-9847-fb3d0675bef4); Time taken: 0.062 seconds INFO : OK +----------------+--+ | database_name | +----------------+--+ | default | | hivedb | | hivedb2 | +----------------+--+ -- 去掉INFO信息 0: jdbc:hive2://hadoop101:10000> set hive.server2.logging.operation.level=NONE; -- 去掉后 0: jdbc:hive2://hadoop101:10000> show databases; +----------------+--+ | database_name | +----------------+--+ | default | | hivedb | | hivedb2 | +----------------+--+ ``` 上面的`set`命令只在当前会话有效,要永久去掉INFO信息在`$hive/conf/hive-site.xml`中添加如下配置,然后重启HiveServer2。 ```xml <property> <name>hive.server2.logging.operation.enabled</name> <value>true</value> </property> <property> <name>hive.server2.logging.operation.level</name> <value>NONE</value> </property> <property> <name>hive.server2.logging.operation.log.location</name> <value>/opt/log/hive/operation_logs</value> </property> ```