大數據BigData之如何配置hive鏈接mysql,把mysql做爲元數據庫?

如何配置hive鏈接mysql,把mysql做爲元數據庫?java

文章目錄
  1.增長mysql數據庫的鏈接配置
  2.修改臨時文件夾的路徑
  3.修改 hive-config.sh
  4.下載MySQL JDBC驅動
  5.在HDFS中建立目錄和設置權限
  6.初始化元數據庫mysql


1.增長mysql數據庫的鏈接配置

<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&amp;useSSL=false</value>
</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>password</value>
  <description>password to use against metastore database</description>
</property>
複製代碼

2.修改臨時文件夾的路徑

找到如下2個配置,並改成正確的路徑:sql

<property> 
 <name>hive.exec.local.scratchdir</name>
 <value>/home/lee/iotmp</value>
 <description>Local scratch space for Hive jobs</description>
 </property>
 <property>
 <name>hive.downloaded.resources.dir</name>
 <value>/home/lee/iotmp</value>
 <description>Temporary local directory for added resources in the remote file system.</description>
 </property>
複製代碼

這裏由於我當前用戶是hduser,因此我在hduser的目錄下建立一個iotmp文件夾,並受權:shell

$ mkdir -p /home/lee/iotmp 
$ chmod -R 775 /home/lee/iotmp
複製代碼

3.修改 hive-config.sh

進入到 hive 的 bin 目錄下 ....../hive/bin/數據庫

$ vi hive-config.sh
複製代碼

在該文件的最前面加入如下配置:jvm

//你的JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 
//你的HADOOP_HOME
export HADOOP_HOME=/usr/local/hadoop
//你的HIVE_HOME
export HIVE_HOME=/usr/local/hive
複製代碼

4.下載MySQL JDBC驅動

$ wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.41/mysql-connector-java-5.1.41.jar
複製代碼

下載完後,把jar包複製到..../hive/lib目錄下面maven


5.在HDFS中建立目錄和設置權限

啓動Hadoop,在Hadoop中建立hive須要用到的目錄並設置好權限:oop

$ hadoop fs -mkdir /tmp
$ hadoop fs -mkdir -p /home/lee/hive/warehouse
$ hadoop fs -chmod g+w /tmp
$ hadoop fs -chmod g+w /home/lee/hive/warehouse
複製代碼

6.初始化元數據庫

進入 你的hive lib 目錄,個人是在/home/lee/hive/lib,初始化Hive元數據對應的MySQL數據庫:spa

$ schematool -initSchema -dbType mysql
複製代碼
相關文章
相關標籤/搜索