1.node01安装mysql
# 安装mysql
yum install -y mysql-server
# 启动mysql服务
service mysqld start
# 开机启动
chkconfig mysqld on
# 登录
mysql
# 授权
use mysql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
delete from user where host != "%";
# 测试使用密码登录
mysql -uroot -p
2.node02安装hive
# 上传并解压
tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/
# 添加环境变量
vi /etc/profile
export HIVE_HOME=/opt/hive
export PATH= ...:$HIVE_HOME/bin
source /etc/profile
# 修改配置文件, 注意用户名密码与mysql一致以及3306端口
vi etc/hive-site.xml
hive.metastore.warehouse.dir
/user/hive_remote/warehouse
hive.metastore.local
false
javax.jdo.option.ConnectionURL
jdbc:mysql://node01:3306/hive_remote?createDatabaseIfNotExist=true
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
root
javax.jdo.option.ConnectionPassword
123
3.上传mysql驱动包并复制到hive的lib目录
cp mysql-connector-java-5.1.32-bin.jar /opt/hive/lib
4.报错
Found class jline.Terminal, but interface was expected
原因:hadoop目录下存在老版本jline
解决:
cp jline-2.12.jar /opt/hadoop/share/hadoop/yarn/lib
5.启动hive并测试hive sql
# 启动hive
hive
# hive sql命令文档
# 查看数据库
show databases;
# 查看表
show tables;
# 建库
create database test;
# 删库
drop database test;
# 建表
CREATE TABLE psn (
id int,
name string,
likes array,
address map
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION ITEMS TERMINATED BY '-'
MAP KEYS TERMINATED BY ':'
LINES TERMINATED BY '\n';
# 查看表结构
desc psn;
# 查看表详细信息
desc formatted psn;
# 删表
drop table psn;
# 加载数据(新开命令号窗口)
vi data
1,小明1,lol-book-movie,beijing:haidian-shanghai:pudong
2,小明2,lol-book-movie,beijing:haidian-shanghai:pudong
3,小明3,lol-book-movie,beijing:haidian-shanghai:pudong
4,小明4,lol-book-movie,beijing:haidian-shanghai:pudong
5,小明5,lol-book-movie,beijing:haidian-shanghai:pudong
6,小明6,lol-book-movie,beijing:haidian-shanghai:pudong
7,小明7,lol-book,beijing:haidian-shanghai:pudong
8,小明8,lol-book,beijing:haidian-shanghai:pudong
9,小明9,lol-book-movie,beijing:haidian-shanghai:pudong
# hive命令加载数据
LOAD DATA LOCAL INPATH '/root/data' INTO TABLE psn;
# 查询
select * from psn;
# 查看数据文件
hdfs dfs -cat /user/hive/warehouse/psn/data
# 说明
# 如果数据文件格式不对不影响加载数据(不进行读检查)