HIVE使用mysql作为外置数据库配置详情

时间:2022-06-27 08:31:22
Hive安装配置(mysql)

安装mysql
hadoop$:sudo apt-get update
hadoop$:sudo apt-get install mysql-server
启动mysql
hadoop$:sudo service mysql start
进入mysql界面
hadoop$:sudo mysql -u root -p
创建hive数据库
mysql>create database hive;
将hive数据库下的所有表的所有权限赋给hadoop用户,并配置mysql为hive-site.xml中的连接密码,然后刷新系统权限关系表
mysql>CREATE USER 'hadoop'@'%' IDENTIFIED BY '123123';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'hadoop'@'%' WITH GRANT OPTION;
mysql>flush privileges;
修改配置文件将地址绑定注释
hadoop$:sudo vi /etc/mysql/my.cnf
找到#bind-addreess =127.0.0.1 注释掉这行就可以了
解压缩hive
hadoop$:sudo tar -zxvf /home/bigdata/hive-2.1.tar.gz -C /opt/modules
设置hive的环境变量
hadoop$:vi /etc/profile
如下
export HIVE_HOME=/opt/modules/hive-0.12.0
export PATH=$HIVE_HOME/bin:$PATH
修改hive-site.xml,先要拷贝出一份hive-site.xml,默认是没有的
hadoop$:cp hive-site.xml.template hive-site.xml
hadoop$:vi hive-site.xml
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hadoop</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123123</value>
</property>
修改hive-env.sh
hadoop$:cp hive-env.sh.template hive-env.sh
如下:HADOOP_HOME=/opt/modules/hadoop-2.6.0
配置hive-config.sh
如下:
export JAVA_HOME=/opt/modules/jdk1.7.0_79
export HADOOP_HOME=/opt/modules/hadoop-2.6.0
export HIVE_HOME=/opt/modules/hive-0.12.0
启动Hive
hadoop$:hive