在hive中查看表结构时中文注释乱码,分为两种情况,一种是desc $table,一种是show create table $table
1 数据库字符集
检查
mysql> show variables like '%char%';
mysql> show create table COLUMNS_V2;
mysql> show create table TABLE_PARAMS;
修改
mysql> alter database hive character set latin1;
mysql> alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
mysql> alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
这时desc $table应该可以正常显示中文了,但是show create table $table还是乱码,这时有两种选择:
2.1 继续使用hive
修改 org.apache.hadoop.hive.ql.exec.DDLTask,
outStream.writeBytes(createTab_stmt.toString());
->
outStream.write(createTab_stmt.toString().getBytes(“UTF-8”));outStream.writeBytes(createTab_stmt.render());
->
outStream.write(createTab_stmt.render().getBytes(“UTF-8”));
并重新打包替换hive-exec.jar,改动太大不建议