1.修改conf下的配置文件
cp -a hive-default.xml.template hive-site.xml
2.进入bin目录启动hive
./hive
报错
Exception in thread "main" java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
解决方法:
解决方法:删除/home/hadoop/cloud/apache-hive-2.1.1-bin目录下 rm -rf metastore_db/
再初始化:./bin/schematool -initSchema -dbType derby
Hive本身自带一个数据库,但是有弊端,hive本身数据库,每次只允许一个用户登录
设置mysql关联hive
安装mysql:
将mysql连接驱动放到hive /lib 下
赋予所有表上的权限给root用户,%表示所有的主机都可以访问,密码是root:
[plain] view plain copy
grant all on *.* to root@'%' identified by 'root';
grant all on *.* to root@'Master' identified by 'root';
修改hive-site.xml
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://node1/hive</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
</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>root</value>
<description>password to use against metastore database</description>
</property>
Hive2需要hive元数据库初始化
schematool -dbType mysql -initSchema
元数据库初始化完成后,就可以进入hive了
create table t_emp(
id int,
name string,
age int,
dept_name string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';
load data local inpath '/opt/data/emp_test' into table t_emp;//上传文件
select count(1) from t_emp; //运行一个任务