文章目录
一、Hadoop-Hive-快速入门
-
启动Hive
-
hive-创建数据库
create database test_db;
-
如何查看
-
连接mysql数据库
mysql -uroot -p 输入密码
-
查看hive数据库
show databases;
- 这边的数据库名称是hive-site.xml配置的数据库名称
-
使用hive数据库
use hadoop_hive
-
查看表
show tables
- DBS:存放hive数据库的信息
-
查询DBS的表数据
select * from DBS \G;
- 可以看到有个hive的默认数据库和刚我们创建的数据库
-
-
-
hive-使用数据库
use test_db;
-
创建表
CREATE TABLE `helloworld` (`id` int,`name` string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
问题:
-
使用命令创建的时候,注意表名、字段名需要使用引号,否则会报:
ParseException line 1:45 cannot recognize input near 'ROW' 'FROMAT' 'DELIMITED' in table row format specification
-
Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:An exception was thrown while adding/validating class(es) : Column length too big for column ‘TYPE_NAME’ (max = 21845); use BLOB or TEXT instead
-
因为数据库编码问题,需要将hives数据库中的编码字符集设置成latin1
-
查看hives数据库字符集
show variables like '%char%';
-
修改字符集
alter database hadoop_hive character set latin1;
-
再去hive控制台创建表,发现可以成功。
-
-
-
-
加载数据
load data local inpath '/big_data_learn/data/helloworld.txt' overwrite into table helloworld;
-
查看数据
-
查看记录数
select count(1) from helloworld;
-
控制台
-
YARN页面显示
-