目录

  • ​​准备工作​​
  • ​​1. 进入到hive的conf目录下​​
  • ​​2. 启动hadoop集群​​
  • ​​3. 启动mysql​​
  • ​​4. 启动hive​​
  • ​​5. 在hive中创建demo01这张表​​
  • ​​6. 在mysql中再次查看数据库​​

准备工作

  1. ​拷贝mysql-connector-java-5.1.37-bin.jar包到hive/lib/目录下 ​
  2. hive版本2.7(与版本3.x略微不同)

​​驱动下载链接​​

1. 进入到hive的conf目录下

​新建文件:​​ vim hive-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 存储元数据mysql相关配置 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value> jdbc:mysql://node1:3306/hive?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8</value>
</property>

<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>

<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>

<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hadoop</value>
</property>

<!-- 关闭元数据存储授权 -->
<property>
<name>hive.metastore.event.db.notification.api.auth</name>
<value>false</value>
</property>

<!-- 关闭元数据存储版本的验证 -->
<property>
<name>hive.metastore.schema.verification</name>
<value>false</value>
</property>
</configuration>

2. 启动hadoop集群

[hadoop@hadoop202 hadoop-2.7.2]$ sbin/start-yarn.sh 
[hadoop@hadoop202 hadoop-2.7.2]$ sbin/start-dfs.sh

3. 启动mysql

​这时的mysql没有metastore这个数据库​

[hadoop@hadoop202 hadoop-2.7.2]$ mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)

4. 启动hive

[hadoop@hadoop202 hadoop-2.7.2]$ bin/hive

5. 在hive中创建demo01这张表

show tables;
create table demo01(id int);
show tables;

6. 在mysql中再次查看数据库

​这时mysql有了metastore这个数据库​

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| metastore |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
mysql> use metastore;
mysql> show tables;
# 可以看见刚刚创建好的demo01这张表
mysql> select * from demo01;