hive执行方式
hive默认的列与列的分隔符:^A
tab
\n
^A \001 u/0001 SOH
^b \002
hive的执行方式
1.hive在cli端执行
2.linux命令行
3.执行hive的hql脚本
4.java+驱动来链接hive
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)
变量
env:环境变量,只读
system:系统变量,包括jdk、jvm。可读可写
hiveconf:hive的属性变量。可读可写。
hivevar:hive的用户自定义变量。可读可写
//查看有哪些变量
hive>set
//在hive外面执行
hive --database aaa --hivevar min_limit=1 -e 'select * from b limit ${hivevar:min_limit}'
导出
vi /home/hadoop/aaa.hql
aaa.hql内容如下:
//不写local directory 是写在hdfs上
insert overwrite local directory '/home/hadoop/aaa'
row format delimited fields terminated by '\t'
select * from aa
where id > 5
limit ${hivevar:m_lim}
执行
hive --database xxx --hivevar m_lim=2 -f /home/hadoop/aaa.hql
使用>>来导出
hive --database xxx --hivevar min_limit=1 -e 'select * from u3 limit $
${hivevar:min_limit}'>/home/hadoop/bbb
注意
–hivevar 和 --hiveconf 可以一起使用
每个参数前面都需要 --hivevar 或者 --hiveconf
-e 紧跟语句,-f 紧跟文件
hive的数据同步
1.第一台机器配置hive-site.xml文件保持原来不用管。
2.把hive传到mini2,mini3
scp -r hive mini2:/home/hadoop/apps
scp -r hive mini3:/home/hadoop/apps
3.修改mini2和mini3的/etc/profile文件,把hive信息配置好。
4.配置mini2和mini3的hive-site.xml
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://mini1:9083</value>
</property>
5.启动服务(mini1)
hive --service metastore
6.使用另外两台机器进入hive,查看是否同步