mysql与hive的连接错误

Posted

技术标签:

【中文标题】mysql与hive的连接错误【英文标题】:mysql connection error with hive 【发布时间】:2014-11-17 08:47:59 【问题描述】:

当我尝试使用 hive 远程连接 mysql(从 hadoop-2.5.1 集群中的数据节点)时,它会抛出错误:

Caused by: java.sql.SQLException: Unable to open a test connection to the given database. JDBC url = jdbc:mysql://192.168.4.43:3306/metastore ? createDatabaseIfNotExist=true, username = root. Terminating connection pool. Original Exception: ------
java.sql.SQLException: null,  message from server: "Host 'ravi' is not allowed to connect to this MySQL server"
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1110)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.getProxy(RetryingMetaStoreClient.java:72)
    at org.apache.hadoop.hive.ql.metadata.Hive.createMetaStoreClient(Hive.java:2372)
    at org.apache.hadoop.hive.ql.metadata.Hive.getMSC(Hive.java:2383)
    at org.apache.hadoop.hive.ql.metadata.Hive.getDatabase(Hive.java:1139)
Caused by: java.sql.SQLException: null,  message from server: "Host 'ravi' is not allowed to connect to this MySQL server"
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1110)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
14/11/17 14:06:53 INFO ql.Driver: </PERFLOG method=task.DDL.Stage-0 start=1416213412561 end=1416213413277 duration=716>
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
14/11/17 14:06:53 ERROR ql.Driver: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

如果有人有解决方案,请告诉我。 提前谢谢

【问题讨论】:

【参考方案1】:

您必须从命令行为 ravi 创建新的 mysql 用户,如下所示:

CREATE USER 'ravi'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'ravi'@'localhost' WITH GRANT OPTION;
CREATE USER 'ravi'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'ravi'@'%' WITH GRANT OPTION;

根据您的环境更改适当的值并使用 hive 重试查询。

【讨论】:

我从 mysql 收到这种错误:mysql> CREATE USER 'ravi'@'192.168.4.43' IDENTIFIED BY 'root';错误 1396 (HY000): 'ravi'@'192.168.4.43' 的操作 CREATE USER 失败

以上是关于mysql与hive的连接错误的主要内容,如果未能解决你的问题,请参考以下文章

DataGrip连接Hive异常

hive连接MySQL报错

hive连接远程hadoop使用查询语句时,发生错误

Hive 中的多个表连接出现错误 - 连接中遇到左右别名

Hive 与 MySQL 的连接:用户 'hive'@'localhost' 配置单元的访问被拒绝

与 Hive 的 Python 连接