搭建HIVE数据仓库导入带有中文的HQL及查看表数据时遇到的乱码问题

1、在搭建hive数据仓库完成后,desc 表名 字段描述乱码

搭建HIVE数据仓库导入带有中文的HQL及查看表数据时遇到的乱码问题_第1张图片

以及导入带有中文HQL时报错

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: Transaction failed to commit
        at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:451)
        at org.datanucleus.api.jdo.JDOTransaction.rollback(JDOTransaction.java:186)
        at org.apache.hadoop.hive.metastore.ObjectStore.rollbackTransaction(ObjectStore.java:539)
        at org.apache.hadoop.hive.metastore.ObjectStore.createTable(ObjectStore.java:893)
        at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:98)
        at com.sun.proxy.$Proxy10.createTable(Unknown Source)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.create_table_core(HiveMetaStore.java:1411)
        at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.create_table_with_environment_context(HiveMetaStore.java:1444)


2、查看下mysql的字符集

show variables like '%char%';

搭建HIVE数据仓库导入带有中文的HQL及查看表数据时遇到的乱码问题_第2张图片

3、修改mysql字符集

[root@hadoop01 etc]# cat /etc/my.cnf
[client]
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
init_connect='SET NAMES utf8'
user=mysql
symbolic-links=0
#skip-grant-tables
max_connections=2000
log-bin=mysql-bin
server-id=11
binlog_format = MIXED
[mysql]
no-auto-rehash
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

重启启动mysql、hive服务

4、再次查看mysql字符集

搭建HIVE数据仓库导入带有中文的HQL及查看表数据时遇到的乱码问题_第3张图片

都变成utf8了

5、导入、查看hive数据正常

你可能感兴趣的:(Hive)