溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

hive連MySQL數(shù)據(jù)庫創(chuàng)建表時報錯該怎么辦

發(fā)布時間:2021-12-02 09:37:37 來源:億速云 閱讀:355 作者:柒染 欄目:大數(shù)據(jù)

hive連MySQL數(shù)據(jù)庫創(chuàng)建表時報錯該怎么辦,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

1. 報錯信息:
    2018-06-01 14:44:20,644 ERROR [main]: DataNucleus.Datastore (Log4JLogger.java:error(115)) - Error thrown executing CREATE TABLE `TABLE_PARAMS`
    (
        `TBL_ID` BIGINT NOT NULL,
        `PARAM_KEY` VARCHAR(256) BINARY NOT NULL,
        `PARAM_VALUE` VARCHAR(4000) BINARY NULL,
        CONSTRAINT `TABLE_PARAMS_PK` PRIMARY KEY (`TBL_ID`,`PARAM_KEY`)
    ) ENGINE=INNODB : Specified key was too long; max key length is 767 bytes
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Specified key was too long; max key length is 767 bytes
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
            at com.mysql.jdbc.Util.getInstance(Util.java:381)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
            at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
            at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
            at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
            at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
            at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:741)
            at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:587)
            at com.jolbox.bonecp.StatementHandle.execute(StatementHandle.java:254)
            at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatement(AbstractTable.java:760)
            at org.datanucleus.store.rdbms.table.AbstractTable.executeDdlStatementList(AbstractTable.java:711)
            at org.datanucleus.store.rdbms.table.AbstractTable.create(AbstractTable.java:425)
            at org.datanucleus.store.rdbms.table.AbstractTable.exists(AbstractTable.java:488)
            at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.performTablesValidation(RDBMSStoreManager.java:3380)
            at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.addClassTablesAndValidate(RDBMSStoreManager.java:3190)
            at org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2841)
            at org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:122)


2. 解決方案:
    在MySQL數(shù)據(jù)庫修改“hive數(shù)據(jù)庫”的編碼,在MySQL下執(zhí)行命令:alter database  hive數(shù)據(jù)庫  character set latin1;  
    hive啟動后,MySQL數(shù)據(jù)庫里面會創(chuàng)建指定的數(shù)據(jù)庫,ruozedb是在hive.site.xml文件中的MySQL連接URL指定的數(shù)據(jù)庫。 
    2.1 登錄MySQL數(shù)據(jù)庫查看Database:
        mysql> show databases;
        +--------------------+
        | Database           |
        +--------------------+
        | information_schema |
        | mysql              |
        | performance_schema |
        | ruozedb            |
        | test               |
        +--------------------+
        5 rows in set (0.00 sec)


    2.2 在MySQL數(shù)據(jù)庫執(zhí)行如下操作:

        mysql> alter database ruozedb character set latin1;
        Query OK, 1 row affected (0.00 sec)
        
    2.3 在hive里面執(zhí)行創(chuàng)建腳本
        hive> show databases;
        OK
        default
        Time taken: 2.158 seconds, Fetched: 1 row(s)
        hive> create table psn_info(id int ,name varchar(200),age int , tel varchar(20),email varchar(100));
        OK
        Time taken: 2.913 seconds
        hive> show tables;
        OK
        psn_info
        Time taken: 0.132 seconds, Fetched: 1 row(s)

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI