上传hive安装包并解压
给hive设置一个软链接
给hive配置环境变量
sudo vim /etc/profile
#hive
export HIVE_HOME=/opt/modules/hive
export PATH=$PATH:$HIVE_HOME/bi
使环境变量生效
source /etc/profile
修改hive的配置文件
拷贝驱动mysql-connector-java-5.1.17.jar到 /opt/modules/hive/lib
这个是hive的配置文件初始情况
我们通过notepad++来连接到我们的集群,方便修改配置文件
重命名
mv hive-default.xml.template hive-default.xml
mv hive-default.xml hive-site.xml
修改hive-site.xml文件
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.86.131:3306/hive_metadata?createDatabaseIfNotExist=true</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
重命名
mv hive-env.sh.template hive-env.sh
修改hive/bin目录下的hive-config.sh文件
把jdk hadoop hive的环境变量添加进去
export JAVA_HOME=/opt/modules/jdk1.8.0_65
export HIVE_HOME=/opt/modules/hive
export HADOOP_HOME=/opt/modules/hadoop-2.6.0
修改hive-site.xml
${system:java.io.tmpdir}全部替换成/home/hadoop/hive
${system:user.name}全部替换成hadoop
创建目录
创建数据库表到mysql里面
schematool -initSchema -dbType mysql
启动hive
在Hive里面创建一个表
hive> create table t1(id int)
> ;
OK
Time taken: 1.539 seconds
hive> show tables;
OK
t1
Time taken: 0.105 seconds, Fetched: 1 row(s)
hive>
创建hive的数据库
$hive>create database mydb2 ; //
$hive>show databases ;
$hive>use mydb2 ;
$hive>create table mydb2.t(id int,name string,age int);
$hive>drop table t ;
$hive>drop table mydb2.t ;
$hive>select * from mydb2.t ; //查看指定库的表
$hive>exit ; //退出
$>hive //hive --service cli
$>hive
创建数据库
使用该数据库并在该数据库下创建表
给该表插入数据
insert into t(id,name,age) values(1,'tom',20);