hadoop 笔记(hive)
//**********************************
//安装配置
1. 修改配置文件
1.1 在conf文件夹下
touch hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hivedb?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>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>
2. 拷贝mysql驱动包 至 hive/lib下
3. 修改环境变量 ~/.bashrc
export HIVE_HOME=/data/apache-hive-2.3.2-bin
export HADOOP_HOME=/data/hadoop/hadoop-3.0.0
export PATH=$PATH:$HIVE_HOME/bin
注意HADOOP_HOME也是必须要设置的
4. 初始化数据库
schematool -dbType mysql -initSchema
备注:当前采用mysql作为hive的元数据库
1. 出现问题:rg.apache.hadoop.hive.metastore.HiveMetaException: Failed to get schema version.
解决方法进入mysql:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';
flush privileges;
//**********************************
//基本操作
1. 启动客户端
hive --service cli
2. 创建并使用数据库
create database testdb;
use testdb;
备注:出现错误:Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
原因未出生化数据库
3. 创建一张表
create table users(username string, password string, age int) row format delimited fields terminated by ",";
4. 插入数据
4.1 创建一个数据note.txt
'fred','fred', 30
'sinny', 'sinny', 29
4.2 执行load命令
load data local inpath "/data/data/note.txt" into table users;
遇到问题:
1. There are 0 datanode(s) running and no node(s) are excluded in this operation.
hadoop datanode未启动
解决方案:删除/tmp下hadoop相关文件;删除/usr/local/hadoop/tmp文件 重启
2. 提示hadoop处于安全模式
./hdfs dfsadmin -safemode leave #无用
bin/hadoop fsck / #无用
在hdfs-site.xml中设置安全阀值属性,属性值默认为0.999f,如果设为1则不进行安全检查 # 可以
5. 查询命令
select * from users;