Access denied for user 'cuba'@'localhost' (using password: YES)

Hi,

I have a question.
I try to build a project with Cuba-CLI, for this I choose mysql-database.
The mysql database is in cloud, where I get a connection on it, also where I need a ssl connection too.

Now,
I replace some information in the gradle task, when I assemble the project, means
the host, user etc. in the tasks:
createDb, updateDb

When I try to run the command later:
gradlew setupTomcat deploy start

I get this error:

    ERROR: Cannot check database. See the stacktrace below for details.
    ===================================================================
            at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.checkDatabaseOnStart(DbUpdaterImpl.java:117) ~[cuba-core-6.9.4.jar:6.9.4]
            at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.applicationInitialized(DbUpdaterImpl.java:81) ~[cuba-core-6.9.4.jar:6.9.4]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
            at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:256) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
            at com.haulmont.cuba.core.sys.EventsImpl.publish(EventsImpl.java:33) ~[cuba-global-6.9.4.jar:6.9.4]
            at com.haulmont.cuba.core.sys.AbstractAppContextLoader.initAppContext(AbstractAppContextLoader.java:66) ~[cuba-global-6.9.4.jar:6.9.4]
            at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:75) ~[cuba-global-6.9.4.jar:6.9.4]
            at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) [catalina.jar:8.5.23]
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) [catalina.jar:8.5.23]
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.23]
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) [catalina.jar:8.5.23]
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) [catalina.jar:8.5.23]
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) [catalina.jar:8.5.23]
            at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1144) [catalina.jar:8.5.23]
            at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1878) [catalina.jar:8.5.23]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_151]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_151]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
            at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
    Caused by: com.haulmont.cuba.core.sys.DbInitializationException: Error connecting to database: Cannot create PoolableConnectionFactory (Access denied for user 'cuba'@'localhost' (using password: YES))
            at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.dbInitialized(DbUpdaterEngine.java:180) ~[cuba-core-6.9.4.jar:6.9.4]
            at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterImpl.checkDatabaseOnStart(DbUpdaterImpl.java:98) ~[cuba-core-6.9.4.jar:6.9.4]
            ... 29 common frames omitted
    Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'cuba'@'localhost' (using password: YES))
            at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2303) ~[tomcat-dbcp.jar:8.5.23]
            at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2043) ~[tomcat-dbcp.jar:8.5.23]
            at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1543) ~[tomcat-dbcp.jar:8.5.23]
            at com.haulmont.cuba.core.sys.jdbc.ProxyDataSource.getConnection(ProxyDataSource.java:35) ~[cuba-core-6.9.4.jar:6.9.4]
            at com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.dbInitialized(DbUpdaterEngine.java:159) ~[cuba-core-6.9.4.jar:6.9.4]
            ... 30 common frames omitted
    Caused by: java.sql.SQLException: Access denied for user 'cuba'@'localhost' (using password: YES)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_151]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_151]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_151]
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_151]
            at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327) ~[mysql-connector-java-5.1.38.jar:5.1.38]
            at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) ~[tomcat-dbcp.jar:8.5.23]
            at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:257) ~[tomcat-dbcp.jar:8.5.23]
            at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2313) ~[tomcat-dbcp.jar:8.5.23]
            at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2299) ~[tomcat-dbcp.jar:8.5.23]
            ... 34 common frames omitted 

Does anybody have an idea, how to solve this problem?

Could it be, that I failed a task before, like updateDb? createDb? Because it happen, when I try to “login” with admin??

Thanks

Running tomcat takes database connection parameters from context.xml file(s).
Have you changed parameters in context.xml?

Hi Alex,

I have the same Problem…
where I have to Change the “context”? In which Folders? When I did so, and Restart the tomcat, my context.xml was overriden like before…?
So, when I Change user Cuba to whatever, and rerun the Operation, it will be again Cuba…

A CUBA project has a context.xml file in source code.
For example, here it is in “sample-booking” project:

Yes,

If I change:
username and Password, also the url.
When I safe this file and
“rerun” the Operation of the deployment, I also get this Problem above and when I open this file once again,
I see that
username and Password have the value “Cuba”…

so the changes will be overriden when I run the Operation

Any other tip?
I also did the same like above, create an app, change my Information of database in gradle file, then create db and later deploy…

@bape.king ,

if you find the answear, just let me know, thank you

C:\Users\xxxx\Desktop\sales\modules\core\web\META-INF\context.xml

this file will be always overriden

<Context>

    <!-- Database connection -->
    <Resource
      name="jdbc/CubaDS"
      type="javax.sql.DataSource"
      maxTotal="20"
      maxIdle="2"
      maxWaitMillis="5000"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost/ucdb?useSSL=false&amp;allowMultiQueries=true"
      username="cuba"
      password="cuba"/>

    <!-- Switch off session serialization -->
    <Manager pathname=""/>

</Context> 

but I need instead another username, password and url…and if I safe it, and try the operation, same error like above and file is overriden

Solved.

Following steps:

  • create-app
  • modify gradle-script with right database parameters
  • modify right file in core/web…folder and change the values in the context.xml
  • gradlew assemble
  • gradlew createDb

and then,
gradlew setupTomcat deploy start

the error will not occur (for moment :wink: )