关于中文乱码问题,我们可以从以下几个方面进行考虑:
删除表
drop table t_user03;
创建表设置编码和注释
CREATE TABLE t_user03 (
id INT COMMENT 'ID',
name STRING COMMENT '姓名'
)
COMMENT '用户信息表';
查看表中字段注释
desc t_user03;
查看表和字段注释
use zdb;
describe formatted t_user03;
查看配置编码
show VARIABLES like 'char%'
如图
如果不是可以修改配置文件
进入 etc目录下打开 my.cnf
文件 ,对 my.cnf
添加以下语句:
[client]
default-character-set=utf8mb4
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8_general_ci
在 Mysql 修改Hive元数据表注释和字段注释的编码为 utf-8 在Hive的元数据库(MySQL)中运行: 修改表字段注解和表注解
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(1000) character set utf8;
修改分区字段注解
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(1000) character set utf8;
修改索引注解
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(1000) character set utf8;
在 Hive 的配置文件 hive-site.xml 中,我们可以通过指定字符集编码来解决中文乱码问题。
以下是一个示例:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/metastore?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8</value>
<description>database username for metastore</description>
</property>
我们通过设置 useUnicode=true
和 characterEncoding=UTF-8
来指定使用 UTF-8 字符集编码。
我们通过设置 hive.cli.encoding
参数的值为 UTF-8
来指定字符集编码。这个参数可用于指定各种 CLI 输出数据的字符集编码,例如控制台输出、日志和报告等。
在 hive-site.xml 配置文件中,也可以通过以下两个参数来指定字符集编码:
<property>
<name>hive.cli.print.header</name>
<value>true</value>
<description>Whether to print the names of the columns in query output.</description>
</property>
<property>
<name>hive.cli.encoding</name>
<value>UTF-8</value>
<description>Character-set encoding for various CLI output data such as console output, logs, reports.</description>
</property>
<property>
<name>hive.charset</name>
<value>utf8</value>
<description>The character set encoding to use for data read/write operations.</description>
</property>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有