文章目录
- 一. 设置mysql中的hive库
- 二. hive-site.xml 设置
- 三. 测试
hive支持中文需要关注两个方面:
- 设置hive 元数据库中的一些表
- 设置hive-site.xml.
一. 设置mysql中的hive库
use hivedb;alter table TBLS modify column TBL_NAMEvarchar(1000)character set utf8;alter table COLUMNS_V2 modify column COMMENTvarchar(256)character set utf8;alter table TABLE_PARAMS modify column PARAM_VALUEvarchar(4000)character set utf8;alter table PARTITION_PARAMS modify column PARAM_VALUEvarchar(4000)character set utf8;alter table PARTITION_KEYS modify column PKEY_COMMENTvarchar(4000)character set utf8;alter table INDEX_PARAMS modify column PARAM_VALUEvarchar(4000)character set utf8;二. hive-site.xml 设置
由于Hive元数据(表的属性、字段定义等)都是存储在Mysql中,所以在mysql连接中设置支持中文
characterEncoding=UTF-8
具体的在hive-site.xml中:
<property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://ip:3306/hivedb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false</value><description>JDBC connect stringfora JDBC metastore</description></property><property><name>hive.metastore.readonly.ConnectionURL</name><value>jdbc:mysql://ip:3306/hivedb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false</value></property>三. 测试
重启hive-server
jps kill-9hive_server_pid nohup./hive--service hiveserver2>>/tmp/hiveserver2.log2>&1建表
create tableifnot existsstudentno(stuno string comment'学号',stuname1 string comment'姓名')comment'学生信息表';hive>show create table studentno;OK CREATE TABLE `studentno`(`stuno` string COMMENT'学号',`stuname1` string COMMENT'姓名')COMMENT'学生信息表'。。。 Time taken:0.059seconds,Fetched:15row(s)插入数据
insert into studentnovalues('一号','gao1');hive>select*from studentno;OK 一号 gao1注:含有中文列的表(报错)
create tablestudent(`学号` string comment'学号',`姓名` string comment'姓名')comment'学生信息表';FAILED:Execution Error,returncode1from org.apache.hadoop.hive.ql.exec.DDLTask.MetaException(message:Add request failed:INSERT INTO `COLUMNS_V2`(`CD_ID`,`COMMENT`,`COLUMN_NAME`,`TYPE_NAME`,`INTEGER_IDX`)VALUES(?,?,?,?,?))