昆明微信网站建设,历史网站怎么做,广告策划与营销,百度推广电话销售好做吗1. 连接
有三种方式连接 hive#xff1a;
cli#xff1a;直接输入 bin/hive 就可以进入 clihiveserver2、beelinewebui
1.1 hiveserver2/beeline
1、开启 hiveserver2 服务
// 前台运行#xff0c;当 beeline 输入命令时#xff0c;服务端会返回 OK
[roothadoop1 bin]…1. 连接
有三种方式连接 hive
cli直接输入 bin/hive 就可以进入 clihiveserver2、beelinewebui
1.1 hiveserver2/beeline
1、开启 hiveserver2 服务
// 前台运行当 beeline 输入命令时服务端会返回 OK
[roothadoop1 bin]# ./hiveserver2
OK// 后台运行1表示标准日志输出、2表示错误日志输出 如果我没有配置日志的输出路径日志会生成在当前工作目录默认的日志名称叫做 nohup.xxx
nohup hiveserver2 1/home/hadoop/hiveserver.log 2/home/hadoop/hiveserver.err
或者nohup hiveserver2 1/dev/null 2/dev/null
或者nohup hiveserver2 /dev/null 21 2、启动 beeline 客户端连接
[hadoophadoop1 bin]$ ./beeline// 这里为 hadoop 的用户名
beeline !connect jdbc:hive2://hadoop1:10000
Connecting to jdbc:hive2://hadoop1:10000
Enter username for jdbc:hive2://hadoop1:10000: hadoop
Enter password for jdbc:hive2://hadoop1:10000: ******
Connected to: Apache Hive (version 1.2.1)
Driver: Hive JDBC (version 1.2.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://hadoop1:10000 show databases;
------------------
| database_name |
------------------
| default |
| hive_1 |
------------------
2 rows selected (4.183 seconds)
0: jdbc:hive2://hadoop1:10000// 指定用户名连接
beeline -u jdbc:hive2://hadoop1:10000 -n hadoop参考文章Hive学习之路 四Hive的连接3种连接方式 2. 交互式命令
// -e 不进入hive的交互窗口执行sql语句
bin/hive -e select id from student;// -f 执行脚本中的 sql 语句hivef.sql 语句select *from student;
bin/hive -f /opt/module/datas/hivef.sql
bin/hive -f /opt/module/datas/hivef.sql /opt/module/datas/hive_result.txt// 退出
exit、quit// 查看 hdfs 文件系统
dfs -ls /;// 查看本地文件系统
! ls /opt/module/datas;// 查看在hive中输入的所有历史命令一般为当前用户的根目录 /root 或 /home 目录
cat /home/hadoop/.hivehistory// 其他常用命令
show databases;
show tables;
drop table tableName;
desc tableName; // 查看表结构
use default; // 使用数据库3. 常见属性配置
3.1 数据仓库位置
Default 数据仓库的最原始位置是在 hdfs 上的/user/hive/warehouse 路径下修改位置
!--hive-default.xml.template 拷贝到 hive-site.xml文件中--property
namehive.metastore.warehouse.dir/name
value/user/hive/warehouse/value
descriptionlocation of default database for the warehouse/description
/property配置完后需要修改同组用户权限
bin/hdfs dfs -chmod gw /user/hive/warehouse注意重启 hive cli 才会生效 3.2 修改查询结果显示信息
1、新建一张表 student并插入数据
// 以 \t 作为分隔符
[hadoophadoop1 apps]$ vim my_code/student.txt// 检查分隔符
[hadoophadoop1 apps]$ cat -T my_code/student.txt
1001^Izhangshan
1002^Ilishi
1003^Izhaoliu// 创建一张表 student数据以 \t 作为分隔符
hive create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY \t;
OK
Time taken: 0.463 seconds// 从本地导入数据
hive load data local inpath /home/hadoop/apps/my_code/student.txt into table student;
Loading data to table hive_1.student
Table hive_1.student stats: [numFiles1, totalSize39]
OK
Time taken: 0.846 seconds// 查询发现没有显示具体列名等信息
hive select * from student;
OK
1001 zhangshan
1002 lishi
1003 zhaoliu
Time taken: 0.229 seconds, Fetched: 3 row(s)
2、修改 hive-site.xml文件中添加如下配置信息
propertynamehive.cli.print.header/namevaluetrue/value
/propertypropertynamehive.cli.print.current.db/namevaluetrue/value
/property3、重启 hive
// 显示列名
hive (hive_1) select * from student;
OK
student.id student.name
1001 zhangshan
1002 lishi
1003 zhaoliu
Time taken: 1.636 seconds, Fetched: 3 row(s)3.3 Hive 运行日志信息配置
1、默认日志路径/tmp/hadoop/hive.log
2、修改 hive-log4j.properties
[hadoophadoop1 apps]$ cd hive/conf/
[hadoophadoop1 conf]$ ls
beeline-log4j.properties.template hive-env.sh hive-exec-log4j.properties.template hive-site.xml
hive-default.xml.template hive-env.sh.template hive-log4j.properties.template ivysettings.xml
[hadoophadoop1 conf]$ cp hive-log4j.properties.template hive-log4j.properties
[hadoophadoop1 conf]$ vim hive-log4j.properties// 修改日志路径
hive.log.dir/home/hadoop/apps/hive/logs3、重启 hive
3.4 参数配置方式
参数配置有三种方式
修改配置文件对所有会话有效命令行参数仅对本次会话有效即退出 cli 就失效参数声明上同
优先级配置文件 命令行参数 参数声明
系统级的参数log4j必须用前两种方式设定因为参数的读取在会话建立之前就完成了推荐使用第一种方式
配置文件 默认配置文件hive-default.xml 用户自定义配置文件hive-site.xml 注意用户自定义配置会覆盖默认配置另外 hive 配置会覆盖 hadoop 配置因为它会读取 hadoop 配置 命令行参数
即在启动 hive时通过命令行来添加一些参数如
// 格式-hiveconf paramvalue
bin/hive -hiveconf mapred.reduce.tasks10;// 查看配置hive (default) set mapred.reduce.tasks;
mapred.reduce.tasks-1参数声明方式
可以在 HQL 中使用 SET 关键字设定参数
hive (default) set mapred.reduce.tasks100;