Caused by: java.sql.SQLException: Unable to open a test connection to the given database报错无法打开到给定数据库

在启动hive或则其他要连接数据库的时候 ,都有可能遇到这个问题

[hadoop@hadoop001 bin]$ ./hive
Caused by: java.sql.SQLException: Unable to open a test connection to the given database. JDBC url = jdbc:mysql://localhost:3306/hive, 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.MySQLSyntaxErrorException: Unknown database 'hive'

原因:

mysql和hive是在同一台主机所以将ip地址改为本机
在hive-site.xml配置文件中

jdbc:mysql://192.168.24.26:3306/hive_13?characterEncoding=UTF-8
修改为
 jdbc:mysql://master:3306/hive_13?characterEncoding=UTF-8

分析:

有192.168.24.26改为master后 MySQL用户名也随之发生成APP,此时需要在其中对其重新授权;

解决:

方案一:权限问题

可能由于root的权限不够,可以进行如下操作

  1. 以root进入mysql

  2. 赋予root权限:

mysql> GRANTALL PRIVILEGES ON . TO ‘APP’@‘master’

-> IDENTIFIEDBY ‘some_pass’ WITH GRANT OPTION;

//本地操作的权限

mysql> GRANTALL PRIVILEGES ON . TO ’ root ‘@’%’

-> IDENTIFIEDBY ‘some_pass’ WITH GRANT OPTION;

                //远程操作的权限

刷新:

        flush privileges;

注意:因为你的配置有改动,都要重新启动hdfs和mysql
hdfs:./stop-dfs.sh ./start-dfs.sh jps
mysql:service mysql restart
方案二:mysql驱动问题
mysql-connector-java-5.1.21-bin.jar换成较高版本的驱动如mysql-connector-java-6.0.3-bin.jar
下载路径http://ftp.ntu.edu.tw/MySQL/Downloads/Connector-J/

你可能感兴趣的:(Caused by: java.sql.SQLException: Unable to open a test connection to the given database报错无法打开到给定数据库)