截止目前,命令行(CLI)界面常用到的有linux的CLI、hive的CLI、mysql的CLI。而hive的CLI、mysql的CLI都是需要在linux的CLI输入命令hive或者mysql才能进入。
[admin@master ~]$ hive
[admin@master ~]$ mysql
一、在Linux的CLI进行hive交互
1、如何在linux的CLI界面执行hive的命令语句,而不需要进入到hive的CLI中?
在linux的CLI中输入命令hive --help --service cli,可以查询hive的交互命令
[admin@master ~]$ hive --help --service cli
21/05/30 01:32:56 WARN conf.HiveConf: HiveConf of name hive.metastore.local does not exist
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)
[admin@master ~]$
2、常用hive交互命令
(1)hive -d 指定义hive的变量
…
(2)hive -e 指执行hive的SQL命令行。
[admin@master ~]$ hive -e 'show databases'
[admin@master ~]$ hive -e 'select * from sougou.table_partition limit 5'
(3)hive -f 指执行.sql文件
[admin@master ~]$ hive -f 'uidcount.sql'
(4)hive -H 指查看帮助
(5)hive -i 指初始化.sql文件
[admin@master ~]$ hive -i 'uidcount.sql'
(6)hive -S 指切换到交互式shell中的静默模式
(7)hive -v 指详细模式(将执行的SQL回显到控制台)
二、Linux CLI调度Hadoop Mapreduce
…
三、Linux CLI调度Hive
如上已说明linux跟hive是如何交互的,那么我们只需要把需要执行的代码封装到一个linux执行文件(.sh格式),然后执行这个文件即可实现调度。
1、编写linux执行文件(.sh格式)。hive_uidcount.sh文件中,比较常用hive -e或者hive -f。
[admin@master ~]$ vim hive_uidcount.sh
2、使用bash命令执行.sh文件
[admin@master ~]$ bash hive_uidcount.sh