- hive mysql元数据,报错 Specified key w
- 执行建表sql提示Specified key was too l
- MySQL客户端报错1071 - Specified key w
- Specified key was too long; max
- Specified key was too long; max
- Specified key was too long; max
- MySQL[Specified key was too long
- 记录一次Specified key was too long的问
- Funboot安装常见问题
- 报错分析之Specified Key was too long:
-
问题:
spark sql连接hive的元数据(mysql库)时报错:Specified key was too long; max key length is 767 bytes。 -
解决:
其实是mysql数据字符集问题,只要修改mysql中hive元数据库的字符集便可,即alter database dbname character set latin1;可是设置后启动时仍然报错,启动命令如下:
./spark-shell --master local[2] --jars ~/software/mysql-connector-java-5.1.27-bin.jar
原来:
Changing the MySQL settings does not change existing tables. You may
need to convert them
也就是说改变mysql设置,不能改变已经存在的表,需要转换表的编码,
进入mysql(mysql -uroot -proot),查看hive元数据表:show create table PARTITIONS; 发现还是utf8编码。
更改表的编码:
mysql> alter table PARTITIONS convert to character set latin1;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table PARTITION_KEYS convert to character set latin1;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
也可以先删除原来的元数据库,在重新建库:
drop database hive;
create database hive character set latin1;
然后再启动hive,通过mysql命令show create table TBLS;可以看到新生成的元数据信息表的编码都是latin1.
综述: hive命令出现Specified key was too long; max key length is 767 bytes 错误。是由于元数据的编码导致。需要更改元数据库编码。如果元数据库中已经有了数据,不能删除。那么就更改对应的表的编码。如果元数据库为空。那么就删除元数据库。再重新建立数据库,并更改编码,然后再让hive来建表。
更改表的编码方式:
ALTER
TABLE
tbl_name
CONVERT
TO
CHARACTER
SET charset_name;
网友评论