安装CDH在初始化CM数据库的时候出现mysql数据库连接的问题的解决方案
[2018-09-12 16:22:51,787]ERROR 0[main] - com.cloudera.enterprise.dbutil.DbProvisioner.executeSql(DbProvisioner.java) - Exception when creating/dropping database with user 'root' and jdbc url 'jdbc:mysql://10.100.200.40/?useUnicode=true&characterEncoding=UTF-8' java.sql.SQLException: Access denied for user 'root'@'VM200-40' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4332) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1258) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) 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) at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at com.cloudera.enterprise.dbutil.DbProvisioner.executeSql(DbProvisioner.java:296) at com.cloudera.enterprise.dbutil.DbProvisioner.doMain(DbProvisioner.java:104) at com.cloudera.enterprise.dbutil.DbProvisioner.main(DbProvisioner.java:123) [2018-09-12 16:22:51,792]ERROR 5[main] - com.cloudera.enterprise.dbutil.DbProvisioner.main(DbProvisioner.java) - Stack Trace: java.sql.SQLException: Access denied for user 'root'@'VM200-40' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4332) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1258) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790) at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) 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) at com.mysql.jdbc.Util.handleNewInstance(Util.java:377) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at com.cloudera.enterprise.dbutil.DbProvisioner.executeSql(DbProvisioner.java:296) at com.cloudera.enterprise.dbutil.DbProvisioner.doMain(DbProvisioner.java:104) at com.cloudera.enterprise.dbutil.DbProvisioner.main(DbProvisioner.java:123)
我们知道cm的数据库默认使用的是postgresql数据库,但是我们想存储CM上的相关组件的元数据信息我必须吧他存储在mysql这样的关系型数据库当中,所以我们要初始化数据库使用的是下面的命令。
/usr/share/cmf/schema/scm_prepare_database.sh mysql cm -h10.100.200.40 -uroot -proot --scm-host 10.100.200.40 scm scm scm
我采用的是mysql数据库存元数据。从上面的报错我们能看出来是权限的问题。但是那修改了了好多遍还是不管用。最后的解决方法是将原来的mysql的登录密码修改,或者更新操作即可解决问题。解决方法如下;
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; 给数据库赋予远程连接的权限。
update user set Password = password('root') where User='root'; 更新数据库的数据登录的密码。
select Host,User,Password from user where User='root'; 在这里我们可以查看root用户的主句名称,用户和密码
最后刷新一下数据库刚才修改的配置文件即可:
flush privileges;
这样在去执行上面命令就可以执行成功。我们会在数据库当中看到一个cm的数据库创建成功。
至此问题得到解决了。