ubuntu22.04安装hive和mysql

根据系统版本下载mysql
mysql-server_8.0.32-1ubuntu22.04_amd64.deb-bundle.tar
解压

mkdir -p /opt/mysql
tar -xvf  mysql-server_8.0.32-1ubuntu22.04_amd64.deb-bundle.tar -C /opt/mysql

安装
进入/opt/mysql目录,根据依赖关系使用dpkg -i 命令安装包;
安装hive

tar -xvf apache-hive-3.1.2-bin.tar.gz -C /opt
mv  apache-hive-3.1.2-bin hive
chown -R hadoop:hadoop hive
vim /etc/profile
#添加环境变量
export HIVE_HOME=/opt/hive
export PATH=$PATH:$HIVE_HOME/bin
#保存退出
source /etc/profile

将hive-default.xml.template重命名为hive-default.xml:

cd /opt/hive/conf
cp hive-default.xml.template hive-default.xml

新建hive-site.xml,写入如下内容

vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
  <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>
  <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.cj.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>
</configuration>

写入后保存并退出vim编辑器。
下载对应版本的 MySQL jdbc 包:https://dev.mysql.com/downloads/connector/j/
下载完成后,将包从物理机上拖到虚拟机Ubuntu系统中的家目录下的下载文件夹中

对mysql-connector-j_8.0.32-1ubuntu22.04_all.deb文件进行解压缩

使用 sudo dpkg -i mysql-connector-j_8.0.32-1ubuntu22.04_all.deb 命令安装 MySQL Connector/J 软件包时,该软件包将会被解压并放置在 /usr/share/java/ 目录下

将解压缩后的文件mysql-connector-j-8.1.0.jar拷贝到/usr/local/hive/lib目录下:

root@hadoop001:~# dpkg -i mysql-connector-j_8.0.32-1ubuntu22.04_all.deb 
Selecting previously unselected package mysql-connector-j.
(Reading database ... 213804 files and directories currently installed.)
Preparing to unpack mysql-connector-j_8.0.32-1ubuntu22.04_all.deb ...
Unpacking mysql-connector-j (8.0.32-1ubuntu22.04) ...
Setting up mysql-connector-j (8.0.32-1ubuntu22.04) ...
root@hadoop001:~# cd /usr/share/java/
cp mysql-connector-j_8.0.32.jar /usr/local/hive/lib

进入数据库

root@hadoop001:~# cd ~
root@hadoop001:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create user hive identified by 'hive';
Query OK, 0 rows affected (0.05 sec)

mysql> grant all privileges on hive.* to hive@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

初始化hive

root@hadoop001:/opt# cd /opt/hive/
root@hadoop001:/opt/hive# ./bin/schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-3.3.2/share/hadoop/common/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Metastore connection URL:	 jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :	 com.mysql.cj.jdbc.Driver
Metastore connection User:	 hive
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.mysql.sql
Initialization script completed
schemaTool completed
root@hadoop001:/opt/hive/bin# su – Hadoop

在hadoop已经启动的情况下,启动hive

hadoop@hadoop001:/opt/hive/bin$ ./hive
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-3.3.2/share/hadoop/common/lib/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive Session ID = 845c1267-6784-4d20-90b6-56a96758eb95

Logging initialized using configuration in jar:file:/opt/hive/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
Hive Session ID = 6cafe872-7b1a-4ac3-a82a-a2a18d6e255c
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值