前提条件:hadoop环境以及搭建好,并能正常启动
以下是Hive的安装步骤:
1.去官网下载hive: http://archive.apache.org/dist/hive
2.解压hive: tar -zxvf apache-hive-3.0.0-bin.tar.gz -C /hiveSpace/
3.安装mysql
rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm
rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm
安装的时候可能会有冲突,有冲突则删除冲突,
rpm -qa | grep mysql
rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps
修改mysql的密码
/usr/bin/mysql_secure_installation
(注意:删除匿名用户,允许用户远程连接)
登陆mysql
mysql -u root -p 输入密码
4.配置hive
进入到conf目录下:mv hive-default.xml.template hive-site.xml
vim hive-site.xml (清空configuration标签里面的内容)添加以下配置
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://loclahost:3306/hive?createDatabaseIfNotExist=true</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>
5.安装hive和mysq完成后,将mysql的连接jar包拷贝到hive解压后的/lib目录下
如果出现没有权限的问题,在mysql授权(在安装mysql的机器上执行)
mysql -uroot -p
#(执行下面的语句 *.*:所有库下的所有表 %:任何IP地址或主机都可以连接)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
6.第一次需要执行初始化命令,进入hive的bin目录下执行schematool脚本 :./schematool -dbType mysql -initSchema
[root@hive001 bin]# ./schematool -dbType mysql -initSchema
Metastore connection URL: jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 1.2.0
Initialization script hive-schema-1.2.0.mysql.sql
Initialization script completed
schemaTool completed
查看初始化信息:
[root@hive001 bin]# ./schematool -dbType mysql -info
Metastore connection URL: jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Hive distribution version: 1.2.0
Metastore schema version: 1.2.0
schemaTool completed
然后进入到bin目录下执行./give便可以操作hive数据库了
[root@hive001 bin]# ./hive
Logging initialized using configuration in jar:file:/qiaochi/apache-hive-1.2.2-bin/lib/hive-common-1.2.2.jar!/hive-log4j.properties
hive>
hive> show tables;
OK
Time taken: 2.043 seconds
hive>
进入到mysql命令下发现hive数据库表已经生成
mysql> use hive;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_hive |
+---------------------------+
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| COMPACTION_QUEUE |
| COMPLETED_TXN_COMPONENTS |
| DATABASE_PARAMS |
| DBS |
| DB_PRIVS |
| DELEGATION_TOKENS |
| FUNCS |
| FUNC_RU |
| GLOBAL_PRIVS |
注意:此处我使用的hive安装包是1.X版本的,之前我用2.X版本的安装包在第6步初始化数据的时候出现了错误
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
Underlying cause: java.sql.SQLException : Access denied for user 'hive'@'hive001' (using password: YES)
SQL Error code: 1045
Use --verbose for detailed stacktrace.
*** schemaTool failed ***
有博友这样解决的想使用2.X以上的童鞋在遇到问题的时候可以尝试一下此方法:
https://www.cnblogs.com/qifengle-2446/p/6424361.html
类似报错问题可以参考博客:http://www.bubuko.com/infodetail-1834078.html