hive建表报错:Specified key was too long; max key length is 767 bytes,hadoophive

时间:2023-03-10 01:13:51
hive建表报错:Specified key was too long; max key length is 767 bytes,hadoophive

情况描述

Hive建表时报错,元数据存储在mysql中。

报错信息

如下:

FAILED: Execution Error, return code  from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) : Specified key was too long; max key length is  bytes
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is bytes
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:)
at java.lang.reflect.Constructor.newInstance(Constructor.java:)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:)
at com.mysql.jdbc.Util.getInstance(Util.java:)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:)
at com.jolbox.bonecp.StatementHandle.execute(StatementHandle.java:)

解决方法:

修改数据库编码,在mysql机器的上命令行中运行:

alter database hive character set latin1;