Hive2.1.0安装及配置mysql

安装Hive2.1.0

1.准备工作:安装JDK、Hadoop 

2.下载并解压Hive

wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.1.0/apache-hive-2.1.0-bin.tar.gz
cp apache-hive-2.1.0-bin.tar.gz /usr/local
tar -zxvf apache-hive-2.1.0-bin.tar.gz
mv apache-hive-2.1.0-bin.tar.gz hive
sudo chown -R hadoop:hadoop hive

3. 设置Hive环境变量

vi ~/.bashrc

export HIVE_HOME=/usr/local/hive
export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HIVE_HOME/bin

source ~/.bashrc

4. 修改Hive的配置文件

cp conf/hive-default.xml.template hive-site.xml
cp conf/hive-log4j.properties.template hive-log4j.properties
cp conf/hive-exec-log4j.properties.template hive-exec-log4j.properties

5.  修改 hive-site.xml 

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://192.168.53.94:3306/hive_db?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=UTF-8</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>123456</value>
    <description>password to use against metastore database</description>
</property>

6. 修改 hive-site.xml 替换${system:java.io.tmpdir} 和 ${system:user.name}为/home/hadoop/hive/tmp/,否则会报如下错误 

Logging initialized using configuration in file:/usr/local/hive/conf/hive-log4j2.properties Async: true
Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
	at org.apache.hadoop.fs.Path.initialize(Path.java:205)
	at org.apache.hadoop.fs.Path.<init>(Path.java:171)
	at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:631)
	at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:550)
	at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:518)
	at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:705)
	at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
	at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D
	at java.net.URI.checkPath(URI.java:1823)
	at java.net.URI.<init>(URI.java:745)
	at org.apache.hadoop.fs.Path.initialize(Path.java:202)
	... 12 more

7. 为Hive建立相对应的Mysql账户,并赋予足够的权限

CREATE USER 'hive' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' WITH GRANT OPTION;
flush privileges;

8.将mysql-connector-java-5.1.30-bin.jar 放入 $HIVE_HOME/lib下 

9.启动Hive

./bin/hive

10.启动Hive报错(如无请忽略) 

Caused by: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema.
If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))
这是由于没有初始化Hive元数据的数据库,默认情况下,Hive的元数据保存在了内嵌的derby数据库里

执行如下命令方可
./bin/schematool -initSchema -dbType derby

11.测试Hive

create table table_name (
  id                int,
  dtDontQuery       string,
  name              string
);
show tables;

相关推荐