1、上传安装包
把安装包上传到服务器
put -r "D:\apache-hive-2.3.2-bin.tar.gz"
2、解压缩安装包
tar -zxvf apache-hive-2.3.2-bin.tar.gz -C ~/apps/
3、修改配置文件
进入hive配置文件目录
cd /root/apps/apache-hive-2.3.2-bin/conf
vim hive-site.xml
<configuration>
4、将MySQL驱动包(mysql-connector-java-5.1.40-bin.jar)放置在hive的根路径下的lib目录中
路径:/root/apps/apache-hive-2.3.2-bin/lib
5、配置hive环境变量
vim /etc/profile
export HIVE_HOME=/root/apps/apache-hive-2.3.2-bin
export PATH=$PATH:$HIVE_HOME/bin
刷新策略
source /etc/profile
6、初始化
schematool -dbType mysql -initSchema
7、启动/退出hive客户端
启动:hive --service cli
退出:exit;
8、hive基本操作
(1)创建库:create database if not exists mydb;
(2)查看库:show databases;
(3)切换数据库:use mydb;
(4)创建表:create table if not exists t_user(id int, name string) row format delimited fields terminated by ',';
(5)查看表列表:show tables;
(6)查看表结构
desc t_user;
desc extended t_user;
desc formatted t_user;
(7)插入数据:insert into t_user values (1,'aa'), (2,'bb'), (3,'cc');
(8)导入数据:load data local inpath '/root/t_user.txt' into table t_user;
t_user.txt的数据为:
4,tom
5,tony
6,lily
(9)查询数据:select * from t_user;
把安装包上传到服务器
put -r "D:\apache-hive-2.3.2-bin.tar.gz"
2、解压缩安装包
tar -zxvf apache-hive-2.3.2-bin.tar.gz -C ~/apps/
3、修改配置文件
进入hive配置文件目录
cd /root/apps/apache-hive-2.3.2-bin/conf
vim hive-site.xml
<configuration>
<!-- 如果 mysql 和 hive 在同一个服务器节点,那么请更改 hadoop01 为 localhost -->
<property>
<name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://hadoop01:3306/hivedb?createDatabaseIfNotExist=true</value><description>JDBC connect string for a JDBC metastore</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>root</value><description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name><value>root</value><description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value><description>hive default warehouse, if nessecory, change it</description>
</property></configuration>
4、将MySQL驱动包(mysql-connector-java-5.1.40-bin.jar)放置在hive的根路径下的lib目录中
路径:/root/apps/apache-hive-2.3.2-bin/lib
5、配置hive环境变量
vim /etc/profile
export HIVE_HOME=/root/apps/apache-hive-2.3.2-bin
export PATH=$PATH:$HIVE_HOME/bin
刷新策略
source /etc/profile
6、初始化
schematool -dbType mysql -initSchema
7、启动/退出hive客户端
启动:hive --service cli
退出:exit;
8、hive基本操作
(1)创建库:create database if not exists mydb;
(2)查看库:show databases;
(3)切换数据库:use mydb;
(4)创建表:create table if not exists t_user(id int, name string) row format delimited fields terminated by ',';
(5)查看表列表:show tables;
(6)查看表结构
desc t_user;
desc extended t_user;
desc formatted t_user;
(7)插入数据:insert into t_user values (1,'aa'), (2,'bb'), (3,'cc');
(8)导入数据:load data local inpath '/root/t_user.txt' into table t_user;
t_user.txt的数据为:
4,tom
5,tony
6,lily
(9)查询数据:select * from t_user;