一、Hive的简单使用
基本的命令和MySQL的命令差不多
首先在 /opt/datas 下创建数据 students.txt
1001 zhangsan
1002 lisi
1003 wangwu
显示有多少数据库: show databases;
使用某个数据库: use 数据库名称;
显示当前数据库下的表: show tables;
创建数据表 : create table student (idint,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
显示表的结构 : desc student;
从外部导入数据: load data local inpath'/opt/datas/students.txt' into table student;
二、 安装Mysql
将Mysql安装包上传到服务器上,然后解压压缩包,使用命令:unzip mysql-libs.zip
查看系统是否自带Mysql,将系统上的MySQL卸载
然后首先安装Mysql-Server 其中有个重要的目录要查看 里面记录着Mysql的随机密码
mysql的随机密码为:MIgbmURIlR0Uskh9
然后安装Mysql客户端: rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm
启动Mysql服务命令:service mysql start
登录到Mysql上,然后修改密码: set password=password('123456');
OK,退出Mysql之后在重新登录一下,登录成功!
三、Hive配置metastore
首先进入到Hive的安装目录中 /opt/moudles/hive-.....
创建一个文件 hive-site.xml 想里面配置连接Mysql的数据信息 账号 密码 连接地址 、驱动(这个驱动需要拷贝过来)
javax.jdo.option.ConnectionURL
jdbc:mysql://hadoop-senior.zuoyan.com:3306/metastore?createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
root
username to use against metastore database
javax.jdo.option.ConnectionPassword
123456
password to use against metastore database
hive.cli.print.header
true
Whether to print the names of the columns in query output.
hive.cli.print.current.db
true
Whether to include the current database in the Hive prompt.
拷贝连接数据库的驱动:
cp mysql-connector-java-5.1.27-bin.jar /opt/modules/hive-0.13.1/lib/
配置好后执行一下 bin/hive 在mysql数据库中可以看见 hive给自动创建的数据库
查看一下这个数据库中的表
这个就是Hive的元数据所创建的
四、Hive的基本使用
# 查看 所有的数据库
show databases ;
# 创建数据库create databasedb_hive ;
# 创建一张数据表create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
# 显示当前数据库下的所有数据表
show tables ;
# 查看表的结构descstudent ;
# 更详细的查看表的结构descextended student ;
# 也是详细的查看表的结构(格式化 推荐)descformatted student ;
# 使用某个数据库usedb_hive ;
# 将本地的数据导入到数据库中load data local inpath '/opt/datas/students.txt'into tabledb_hive.student ;
# 查看Hive中支持的命令
show functions ;
# 显示某个功能的用法desc function upper;
# 对这个功能的使用来一个Demodesc function extended upper;
# 测试这个函数select id ,upper(name) uname from db_hive.student ;
五、配置Hive的日志
将Hive安装目录中conf下的 hive-log4j.properties.template 重命名
日志默认存放的位置是 系统中的/tmp/${User}/hive.log
故意查询错误一下,然后查看日志
修改Hive日志的存放地址,(在Hive的安装目录中创建logs文件夹用来存放日志,然后配置 hive-log4j.properties 中的 hive.log.dir
hive.log.threshold=ALL
hive.root.logger=INFO,DRFA
hive.log.dir=/opt/modules/hive-0.13.1/logs
hive.log.file=hive.log
设置启动打印日志
bin/hive --hiveconf hive.root.logger=INFO,console
如果以这种方式启动的话,Hive会直接将日志打印在控制台上