Hive 本地模式

版本: hive: 2.3.3
hadoop : 2.6.0

  1. 配置hive-site.xml
  
    javax.jdo.option.ConnectionURL
    jdbc:mysql://10.30.16.201:3306/hivemetalocal?createDatebaseIfNotExist=true
  

  
    javax.jdo.option.ConnectionDriverName
    com.mysql.jdbc.Driver
  
  
    javax.jdo.option.ConnectionUserName
    hiveuser
  
  
    javax.jdo.option.ConnectionPassword
    hive123
  
  
    hive.metastore.local
    true
  


    hive.exec.local.scratchdir
    /var/hive/iotmp/hive
    Local scratch space for Hive jobs


    hive.downloaded.resources.dir
    /var/hive/iotmp/${hive.session.id}_resources
    Temporary local directory for added resources in the remote file system.


    hive.querylog.location
    /var/hive/iotmp/hive
    Location of Hive run time structured log file


    hive.server2.logging.operation.log.location
    /var/hive/iotmp/hive/operation_logs
    Top level directory where operation logs are stored if logging functionality is enabled


  1. 使用命令 schematool -dbType mysql -initSchema , 报错如下:
Metastore connection URL:    jdbc:mysql://10.30.16.201:3306/hivemetalocal?createDatebaseIfNotExist=true
Metastore Connection Driver :    com.mysql.jdbc.Driver
Metastore connection User:   hiveuser
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : Unknown database 'hivemetalocal'
SQL Error code: 1049
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
    at org.apache.hive.beeline.HiveSchemaHelper.getConnectionToMetastore(HiveSchemaHelper.java:77)
    at org.apache.hive.beeline.HiveSchemaTool.getConnectionToMetastore(HiveSchemaTool.java:144)
    at org.apache.hive.beeline.HiveSchemaTool.testConnectionToMetastore(HiveSchemaTool.java:473)
    at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:577)
    at org.apache.hive.beeline.HiveSchemaTool.doInit(HiveSchemaTool.java:563)
    at org.apache.hive.beeline.HiveSchemaTool.main(HiveSchemaTool.java:1145)
    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: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'hivemetalocal'

hivemetalocal 是mysql的数据库名称, 需要事先创建之(mysql连接的用户名和密码、权限已经事先创建!)。

  1. 创建mysql database hivemetalocal :
mysql> create database hivemetalocal;
  1. 重新执行 schematool -dbType mysql -initSchema --verbose , 显示成功
...
beeline> Initialization script completed
schemaTool completed

  1. 执行hive命令,进入交互命令行模式。

注意:

  1. 本地模式的限制: 在多个用户操作同一张表时,可能会出现不一致的情况,比如一个在插入, 一个在删除。
  2. hive.metastore.local 为true 即为本地模式。

你可能感兴趣的:(Hive 本地模式)