创建一个 test.txt,将 test.txt 存储在 test 表中(create table test(id int))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
hive> load data local inpath '/opt/module/hive/tmp_data/test.txt' into table test; Loading data to table default.test Table default.test stats: [numFiles=1, totalSize=11] OK Time taken: 1.355 seconds
hive> select * from test; OK 1 2 3 4 5 NULL Time taken: 0.233 seconds, Fetched: 6 row(s)
beeline> !connect jdbc:hive2://hadoop02:10000 Connecting to jdbc:hive2://hadoop02:10000 Enter username for jdbc:hive2://hadoop02:10000: root Enter password for jdbc:hive2://hadoop02:10000: ****** Connected to: Apache Hive (version 1.2.1) Driver: Hive JDBC (version 1.2.1) Transaction isolation: TRANSACTION_REPEATABLE_READ
测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
0: jdbc:hive2://hadoop02:10000> show tables; +-----------+--+ | tab_name | +-----------+--+ | test | +-----------+--+ 1 row selected (0.096 seconds)
[root@hadoop02 hive]# 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 --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 -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
常用命令
命令行执行 hql
执行完后自动退出
1 2 3 4 5 6 7 8 9 10 11
[root@hadoop02 hive]# bin/hive -e "select * from test;"
Logging initialized using configuration in jar:file:/opt/module/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties OK 1 2 3 4 5 Time taken: 1.208 seconds, Fetched:5 row(s) [root@hadoop02 hive]#
Logging initialized using configuration in jar:file:/opt/module/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties OK 1 2 3 4 5 Time taken: 1.155 seconds, Fetched: 5 row(s)
hive> ! ls /opt/module; hadoop-2.7.2 hive jdk1.8.0_144 zookeeper-3.4.10
查看历史命令
进入当前用户的根目录,查看 .hivehistory 文件
1 2 3 4 5 6 7 8 9 10 11 12
[root@hadoop02 ~]# cat .hivehistory show databaes; show databases; use default; create table stu(id int, name string) row format delimited fields terminated by '\t'; quit; show tables; create table test(id int); show tables; load data local inpath '/opt/module/hive/tmp_data/test.txt' into table test; select * from test; quit;
Logging initialized using configuration in file:/opt/module/hive/conf/hive-log4j.properties hive (default)> set mapred.reduce.tasks; mapred.reduce.tasks=10