Fayson的github: https://github.com/fayson/cdhproject
推荐关注微信公众号:“Hadoop实操”,ID:gh_c4c535955d0f,或者扫描文末二维码。
1.问题描述
默认Hive中创建有中文注释的表时,无论是在Hive CLI还是Hue中该注释显示都会是乱码。如使用以下建表语句:
create external table test_table
(
s1 string comment 'abc',
s2 string comment '你好啊'
)
row format delimited fields terminated by '#'
stored as textfile location '/lilei/test_table';
在Hive CLI中查看如下:

Hue中显示一样,这里省略。
2.解决办法
这个问题是因为mysql中的元数据库表COLUMNS_V2中的字段COMMENT编码问题导致的,需要设置为utf-8,如下所示:

在mysql中设置该字段的编码为utf-8,如下所示:
mysql –u root –p
use metastore;
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
FLUSH PRIVILEGES;

注意Hive元数据这个数据库应使用utf-8创建,如:
create database metastore defaultcharacter set utf8;
回到Hive中重现create一张表

查看该表的注释:

发现中文注释已经显示正常。
查看以前的表:

发现依旧显示为乱码。
需要修改以前的表的comment才能显示正常,在Hive CLI中执行,命令如下:
ALTER TABLE test\_table1 change column s2 s2 STRING COMMENT '我不好';

再次查看旧表的comment:

发现中文注释已经显示正常。问题解决。
为天地立心,为生民立命,为往圣继绝学,为万世开太平。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。
![]()
原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操

网友评论