需求:
??把Hive元數(shù)據(jù)寫道MySQL的metastore數(shù)據(jù)庫中(MySQL默認沒有metastore數(shù)據(jù)庫,需要提前創(chuàng)建:create database metastore;)
??連接地址:jdbc:mysql//hadoop102:3306/metastore
??驅(qū)動:com.mysql.cj.jdbc.Driver
??用戶名:root
??密碼:123456
1 配置元數(shù)據(jù)到MySQL
(1)新建元數(shù)據(jù)庫:
#登錄到MySQL
mysql -u root -p123456
#創(chuàng)建元數(shù)據(jù)庫
mysql>create database metastore;
mysql>quit;
(2)把MySQL的JDBC驅(qū)動拷貝到Hive的lib目錄下(此處用的是MySQL8.0.33的驅(qū)動):
cd /opt/software/mysql-connector-j-8.0.33.jar /opt/module/hive/lib
(3)在$HIVE_HOME/conf下創(chuàng)建hive-site.xml文件:
vim hive-site.xml
#添加以下內(nèi)容:
<?xml version="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- jdbc連接的URL-->
<!--主機名:端口號/數(shù)據(jù)庫名 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop102:3306/metastore?useSSL=false</value>
</property>
<!-- jdbc連接的Driver-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
</property>
<!--jdbc連接的username-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<!-- jdbc連接的password -->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<!-- Hive默認在HDFS的工作目錄-->
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
</configuration>
(4)初始化hive元數(shù)據(jù)庫,改為用MySQL存儲:
bin/schematool -dbType mysql -initSchema -verbose
2 驗證元數(shù)據(jù)是否配置成功
(1)啟動hive:
bin/hive
(2)使用hive:
hive> show databases;
hive> show tables;
hive> create table stu(id int, namestring);
hive> insert into stuvalues(1,"liao");
hive> select * from stu;
(3)在另外一個窗口開啟hive,可以看到兩個窗口都可以操作hive,沒有異常:
hive>show databases;
hive>show tables;
hive>select * from stu;
3 查看MySQL中的元數(shù)據(jù)
(1)登錄MySQL:
mysql -u root -p123456
(2)查看元數(shù)據(jù)庫metastore:
mysql> show databases;
mysql> use metastore;
mysql> show tables;
(i)查看元數(shù)據(jù)中存儲的庫信息,hive中默認有default數(shù)據(jù)庫:
mysql>select * from DBS;
(ii)查看元數(shù)據(jù)中存儲的表信息,TBLS中保存了在hive中創(chuàng)建所有表的信息,創(chuàng)建的表的根目錄等信息保存在SDS表中:
mysql>select * from TBLS;
(iii)查看元數(shù)據(jù)中存儲的列相關(guān)信息,保存創(chuàng)建表的字段的信息:文章來源:http://www.zghlxwxcb.cn/news/detail-702421.html
mysql>select * from COLUMNS_V2;
文章來源地址http://www.zghlxwxcb.cn/news/detail-702421.html
到了這里,關(guān)于【大數(shù)據(jù)之Hive】四、配置Hive元數(shù)據(jù)存儲到MySQL的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!