IDEA连接HIVE,踩坑日志-Failed initialising database.

今天使用idea本地连接Linux的hive数据库遇到了问题,代码如下:

def main(args: Array[String]): Unit = {
val sparkConf = new SparkConf().setAppName(“adver”).setMaster(“local[*]”)
val sparkSession = SparkSession.builder().config(sparkConf)
.enableHiveSupport().getOrCreate()
sparkSession.sql(“show databases”).show(true)
sparkSession.sql(“use test1”)
val rdd = sparkSession.sql(“desc table1”)
rdd.show()
}

问题如下

19/10/25 11:27:29 ERROR Schema: Failed initialising database.
Unable to open a test connection to the given database. JDBC url = jdbc:mysql://mynode:3306/hive?createDataBaseIfNoExist=true, username = root. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
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:423)

后面还有一大堆报错问题的,其中有一句其实是有提示问题解决方法的,但习惯了查看第一句代码出错信息从而去查找解决方法,从网上查找了很多,有说导入hive连接mysql依赖没导,有些说版本不一致,有些说集群没开,还有说是复制的三个文件有问题,眼花缭乱的。
最终本着去Word里面翻译一下全部报错信息,查询结果,意外就出现了!!!
一个大大的不识别指向了我的mynode主机名,然后就恍然大悟,mynode是我在Linux上设置的主机名,可能window不识别,然后我就去C:\Windows\System32\drivers\etc改了hosts文件,加上了ip和名字。
比如:192.168.12.12 mynode,即可。

详细配置在另一篇博客。

你可能感兴趣的:(错误干扰,Linux,Linux,IDEA,HIVE,SPARK)